mirror of
https://github.com/postgres/postgres.git
synced 2025-11-19 13:42:17 +03:00
Massive commit to run PGINDENT on all *.c and *.h files.
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* libpgtcl.h--
|
||||
* libpgtcl is a tcl package for front-ends to interface with pglite
|
||||
* It's the tcl equivalent of the old libpq C interface.
|
||||
* libpgtcl is a tcl package for front-ends to interface with pglite
|
||||
* It's the tcl equivalent of the old libpq C interface.
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: libpgtcl.h,v 1.2 1996/10/30 06:18:37 scrappy Exp $
|
||||
* $Id: libpgtcl.h,v 1.3 1997/09/07 05:03:06 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
#include "tcl.h"
|
||||
|
||||
extern int Pgtcl_Init (Tcl_Interp *interp);
|
||||
extern int Pgtcl_SafeInit (Tcl_Interp *interp);
|
||||
extern int Pgtcl_Init(Tcl_Interp * interp);
|
||||
extern int Pgtcl_SafeInit(Tcl_Interp * interp);
|
||||
|
||||
#endif /* LIBPGTCL_H */
|
||||
#endif /* LIBPGTCL_H */
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* pgtcl.c--
|
||||
*
|
||||
* libpgtcl is a tcl package for front-ends to interface with pglite
|
||||
* It's the tcl equivalent of the old libpq C interface.
|
||||
*
|
||||
* libpgtcl is a tcl package for front-ends to interface with pglite
|
||||
* It's the tcl equivalent of the old libpq C interface.
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtcl.c,v 1.7 1997/01/03 18:48:28 scrappy Exp $
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtcl.c,v 1.8 1997/09/07 05:03:09 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -23,8 +23,8 @@
|
||||
#include "pgtclId.h"
|
||||
|
||||
/*
|
||||
* Pgtcl_Init
|
||||
* initialization package for the PGLITE Tcl package
|
||||
* Pgtcl_Init
|
||||
* initialization package for the PGLITE Tcl package
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -32,153 +32,154 @@
|
||||
* Tidy up forgotten postgres connection at Tcl_Exit
|
||||
*/
|
||||
static void
|
||||
Pgtcl_AtExit (ClientData cData)
|
||||
Pgtcl_AtExit(ClientData cData)
|
||||
{
|
||||
Pg_clientData *cd = (Pg_clientData *)cData;
|
||||
Tcl_HashEntry *hent;
|
||||
Tcl_HashSearch hsearch;
|
||||
Pg_ConnectionId *connid;
|
||||
PGconn *conn;
|
||||
Pg_clientData *cd = (Pg_clientData *) cData;
|
||||
Tcl_HashEntry *hent;
|
||||
Tcl_HashSearch hsearch;
|
||||
Pg_ConnectionId *connid;
|
||||
PGconn *conn;
|
||||
|
||||
while((hent = Tcl_FirstHashEntry(&(cd->dbh_hash), &hsearch)) != NULL) {
|
||||
connid = (Pg_ConnectionId *)Tcl_GetHashValue(hent);
|
||||
conn = connid->conn;
|
||||
PgDelConnectionId(cd, connid->id);
|
||||
PQfinish(conn);
|
||||
}
|
||||
while ((hent = Tcl_FirstHashEntry(&(cd->dbh_hash), &hsearch)) != NULL)
|
||||
{
|
||||
connid = (Pg_ConnectionId *) Tcl_GetHashValue(hent);
|
||||
conn = connid->conn;
|
||||
PgDelConnectionId(cd, connid->id);
|
||||
PQfinish(conn);
|
||||
}
|
||||
|
||||
Tcl_DeleteHashTable(&(cd->dbh_hash));
|
||||
Tcl_DeleteHashTable(&(cd->res_hash));
|
||||
Tcl_DeleteHashTable(&(cd->notify_hash));
|
||||
Tcl_DeleteHashTable(&(cd->dbh_hash));
|
||||
Tcl_DeleteHashTable(&(cd->res_hash));
|
||||
Tcl_DeleteHashTable(&(cd->notify_hash));
|
||||
|
||||
Tcl_DeleteExitHandler(Pgtcl_AtExit, cData);
|
||||
Tcl_DeleteExitHandler(Pgtcl_AtExit, cData);
|
||||
}
|
||||
|
||||
/*
|
||||
* Tidy up forgotten postgres connections on Interpreter deletion
|
||||
*/
|
||||
static void
|
||||
Pgtcl_Shutdown (ClientData cData, Tcl_Interp *interp)
|
||||
Pgtcl_Shutdown(ClientData cData, Tcl_Interp * interp)
|
||||
{
|
||||
Pgtcl_AtExit(cData);
|
||||
Pgtcl_AtExit(cData);
|
||||
}
|
||||
|
||||
int
|
||||
Pgtcl_Init (Tcl_Interp *interp)
|
||||
Pgtcl_Init(Tcl_Interp * interp)
|
||||
{
|
||||
Pg_clientData *cd;
|
||||
Pg_clientData *cd;
|
||||
|
||||
/* Create and initialize the client data area */
|
||||
cd = (Pg_clientData *)ckalloc(sizeof(Pg_clientData));
|
||||
Tcl_InitHashTable(&(cd->dbh_hash), TCL_STRING_KEYS);
|
||||
Tcl_InitHashTable(&(cd->res_hash), TCL_STRING_KEYS);
|
||||
Tcl_InitHashTable(&(cd->notify_hash), TCL_STRING_KEYS);
|
||||
cd->dbh_count = 0L;
|
||||
cd->res_count = 0L;
|
||||
/* Create and initialize the client data area */
|
||||
cd = (Pg_clientData *) ckalloc(sizeof(Pg_clientData));
|
||||
Tcl_InitHashTable(&(cd->dbh_hash), TCL_STRING_KEYS);
|
||||
Tcl_InitHashTable(&(cd->res_hash), TCL_STRING_KEYS);
|
||||
Tcl_InitHashTable(&(cd->notify_hash), TCL_STRING_KEYS);
|
||||
cd->dbh_count = 0L;
|
||||
cd->res_count = 0L;
|
||||
|
||||
/* Arrange for tidy up when interpreter is deleted or Tcl exits */
|
||||
Tcl_CallWhenDeleted(interp, Pgtcl_Shutdown, (ClientData)cd);
|
||||
Tcl_CreateExitHandler(Pgtcl_AtExit, (ClientData)cd);
|
||||
/* Arrange for tidy up when interpreter is deleted or Tcl exits */
|
||||
Tcl_CallWhenDeleted(interp, Pgtcl_Shutdown, (ClientData) cd);
|
||||
Tcl_CreateExitHandler(Pgtcl_AtExit, (ClientData) cd);
|
||||
|
||||
/* register all pgtcl commands */
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_conndefaults",
|
||||
Pg_conndefaults,
|
||||
(ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
|
||||
/* register all pgtcl commands */
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_conndefaults",
|
||||
Pg_conndefaults,
|
||||
(ClientData) cd, (Tcl_CmdDeleteProc *) NULL);
|
||||
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_connect",
|
||||
Pg_connect,
|
||||
(ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_connect",
|
||||
Pg_connect,
|
||||
(ClientData) cd, (Tcl_CmdDeleteProc *) NULL);
|
||||
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_disconnect",
|
||||
Pg_disconnect,
|
||||
(ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
|
||||
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_exec",
|
||||
Pg_exec,
|
||||
(ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
|
||||
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_select",
|
||||
Pg_select,
|
||||
(ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
|
||||
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_result",
|
||||
Pg_result,
|
||||
(ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
|
||||
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_lo_open",
|
||||
Pg_lo_open,
|
||||
(ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
|
||||
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_lo_close",
|
||||
Pg_lo_close,
|
||||
(ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_disconnect",
|
||||
Pg_disconnect,
|
||||
(ClientData) cd, (Tcl_CmdDeleteProc *) NULL);
|
||||
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_lo_read",
|
||||
Pg_lo_read,
|
||||
(ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_exec",
|
||||
Pg_exec,
|
||||
(ClientData) cd, (Tcl_CmdDeleteProc *) NULL);
|
||||
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_lo_write",
|
||||
Pg_lo_write,
|
||||
(ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_select",
|
||||
Pg_select,
|
||||
(ClientData) cd, (Tcl_CmdDeleteProc *) NULL);
|
||||
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_lo_lseek",
|
||||
Pg_lo_lseek,
|
||||
(ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_result",
|
||||
Pg_result,
|
||||
(ClientData) cd, (Tcl_CmdDeleteProc *) NULL);
|
||||
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_lo_creat",
|
||||
Pg_lo_creat,
|
||||
(ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_lo_open",
|
||||
Pg_lo_open,
|
||||
(ClientData) cd, (Tcl_CmdDeleteProc *) NULL);
|
||||
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_lo_tell",
|
||||
Pg_lo_tell,
|
||||
(ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_lo_close",
|
||||
Pg_lo_close,
|
||||
(ClientData) cd, (Tcl_CmdDeleteProc *) NULL);
|
||||
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_lo_unlink",
|
||||
Pg_lo_unlink,
|
||||
(ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_lo_read",
|
||||
Pg_lo_read,
|
||||
(ClientData) cd, (Tcl_CmdDeleteProc *) NULL);
|
||||
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_lo_import",
|
||||
Pg_lo_import,
|
||||
(ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
|
||||
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_lo_export",
|
||||
Pg_lo_export,
|
||||
(ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
|
||||
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_listen",
|
||||
Pg_listen,
|
||||
(ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_lo_write",
|
||||
Pg_lo_write,
|
||||
(ClientData) cd, (Tcl_CmdDeleteProc *) NULL);
|
||||
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_notifies",
|
||||
Pg_notifies,
|
||||
(ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_lo_lseek",
|
||||
Pg_lo_lseek,
|
||||
(ClientData) cd, (Tcl_CmdDeleteProc *) NULL);
|
||||
|
||||
Tcl_PkgProvide(interp, "Pgtcl", "1.0");
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_lo_creat",
|
||||
Pg_lo_creat,
|
||||
(ClientData) cd, (Tcl_CmdDeleteProc *) NULL);
|
||||
|
||||
return TCL_OK;
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_lo_tell",
|
||||
Pg_lo_tell,
|
||||
(ClientData) cd, (Tcl_CmdDeleteProc *) NULL);
|
||||
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_lo_unlink",
|
||||
Pg_lo_unlink,
|
||||
(ClientData) cd, (Tcl_CmdDeleteProc *) NULL);
|
||||
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_lo_import",
|
||||
Pg_lo_import,
|
||||
(ClientData) cd, (Tcl_CmdDeleteProc *) NULL);
|
||||
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_lo_export",
|
||||
Pg_lo_export,
|
||||
(ClientData) cd, (Tcl_CmdDeleteProc *) NULL);
|
||||
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_listen",
|
||||
Pg_listen,
|
||||
(ClientData) cd, (Tcl_CmdDeleteProc *) NULL);
|
||||
|
||||
Tcl_CreateCommand(interp,
|
||||
"pg_notifies",
|
||||
Pg_notifies,
|
||||
(ClientData) cd, (Tcl_CmdDeleteProc *) NULL);
|
||||
|
||||
Tcl_PkgProvide(interp, "Pgtcl", "1.0");
|
||||
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
Pgtcl_SafeInit (Tcl_Interp *interp)
|
||||
Pgtcl_SafeInit(Tcl_Interp * interp)
|
||||
{
|
||||
return Pgtcl_Init(interp);
|
||||
return Pgtcl_Init(interp);
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,11 +1,11 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* pgtclCmds.h--
|
||||
* declarations for the C functions which implement pg_* tcl commands
|
||||
* declarations for the C functions which implement pg_* tcl commands
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: pgtclCmds.h,v 1.6 1997/01/03 18:48:31 scrappy Exp $
|
||||
* $Id: pgtclCmds.h,v 1.7 1997/09/07 05:03:12 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -18,69 +18,89 @@
|
||||
#include "libpq-fe.h"
|
||||
#include "libpq/libpq-fs.h"
|
||||
|
||||
typedef struct Pg_clientData_s {
|
||||
Tcl_HashTable dbh_hash;
|
||||
Tcl_HashTable res_hash;
|
||||
Tcl_HashTable notify_hash;
|
||||
long dbh_count;
|
||||
long res_count;
|
||||
} Pg_clientData;
|
||||
typedef struct Pg_clientData_s
|
||||
{
|
||||
Tcl_HashTable dbh_hash;
|
||||
Tcl_HashTable res_hash;
|
||||
Tcl_HashTable notify_hash;
|
||||
long dbh_count;
|
||||
long res_count;
|
||||
} Pg_clientData;
|
||||
|
||||
|
||||
typedef struct Pg_ConnectionId_s {
|
||||
char id[32];
|
||||
PGconn *conn;
|
||||
Tcl_HashTable res_hash;
|
||||
} Pg_ConnectionId;
|
||||
typedef struct Pg_ConnectionId_s
|
||||
{
|
||||
char id[32];
|
||||
PGconn *conn;
|
||||
Tcl_HashTable res_hash;
|
||||
} Pg_ConnectionId;
|
||||
|
||||
|
||||
typedef struct Pg_ResultId_s {
|
||||
char id[32];
|
||||
PGresult *result;
|
||||
Pg_ConnectionId *connection;
|
||||
} Pg_ResultId;
|
||||
typedef struct Pg_ResultId_s
|
||||
{
|
||||
char id[32];
|
||||
PGresult *result;
|
||||
Pg_ConnectionId *connection;
|
||||
} Pg_ResultId;
|
||||
|
||||
|
||||
/* **************************/
|
||||
/* registered Tcl functions */
|
||||
/* **************************/
|
||||
extern int Pg_conndefaults(
|
||||
ClientData cData, Tcl_Interp *interp, int argc, char* argv[]);
|
||||
extern int Pg_connect(
|
||||
ClientData cData, Tcl_Interp *interp, int argc, char* argv[]);
|
||||
extern int Pg_disconnect(
|
||||
ClientData cData, Tcl_Interp *interp, int argc, char* argv[]);
|
||||
extern int Pg_exec(
|
||||
ClientData cData, Tcl_Interp *interp, int argc, char* argv[]);
|
||||
extern int Pg_select(
|
||||
ClientData cData, Tcl_Interp *interp, int argc, char* argv[]);
|
||||
extern int Pg_result(
|
||||
ClientData cData, Tcl_Interp *interp, int argc, char* argv[]);
|
||||
extern int Pg_lo_open(
|
||||
ClientData cData, Tcl_Interp *interp, int argc, char* argv[]);
|
||||
extern int Pg_lo_close(
|
||||
ClientData cData, Tcl_Interp *interp, int argc, char* argv[]);
|
||||
extern int Pg_lo_read(
|
||||
ClientData cData, Tcl_Interp *interp, int argc, char* argv[]);
|
||||
extern int Pg_lo_write(
|
||||
ClientData cData, Tcl_Interp *interp, int argc, char* argv[]);
|
||||
extern int Pg_lo_lseek(
|
||||
ClientData cData, Tcl_Interp *interp, int argc, char* argv[]);
|
||||
extern int Pg_lo_creat(
|
||||
ClientData cData, Tcl_Interp *interp, int argc, char* argv[]);
|
||||
extern int Pg_lo_tell(
|
||||
ClientData cData, Tcl_Interp *interp, int argc, char* argv[]);
|
||||
extern int Pg_lo_unlink(
|
||||
ClientData cData, Tcl_Interp *interp, int argc, char* argv[]);
|
||||
extern int Pg_lo_import(
|
||||
ClientData cData, Tcl_Interp *interp, int argc, char* argv[]);
|
||||
extern int Pg_lo_export(
|
||||
ClientData cData, Tcl_Interp *interp, int argc, char* argv[]);
|
||||
extern int Pg_listen(
|
||||
ClientData cData, Tcl_Interp *interp, int argc, char* argv[]);
|
||||
extern int Pg_notifies(
|
||||
ClientData cData, Tcl_Interp *interp, int argc, char* argv[]);
|
||||
extern int
|
||||
Pg_conndefaults(
|
||||
ClientData cData, Tcl_Interp * interp, int argc, char *argv[]);
|
||||
extern int
|
||||
Pg_connect(
|
||||
ClientData cData, Tcl_Interp * interp, int argc, char *argv[]);
|
||||
extern int
|
||||
Pg_disconnect(
|
||||
ClientData cData, Tcl_Interp * interp, int argc, char *argv[]);
|
||||
extern int
|
||||
Pg_exec(
|
||||
ClientData cData, Tcl_Interp * interp, int argc, char *argv[]);
|
||||
extern int
|
||||
Pg_select(
|
||||
ClientData cData, Tcl_Interp * interp, int argc, char *argv[]);
|
||||
extern int
|
||||
Pg_result(
|
||||
ClientData cData, Tcl_Interp * interp, int argc, char *argv[]);
|
||||
extern int
|
||||
Pg_lo_open(
|
||||
ClientData cData, Tcl_Interp * interp, int argc, char *argv[]);
|
||||
extern int
|
||||
Pg_lo_close(
|
||||
ClientData cData, Tcl_Interp * interp, int argc, char *argv[]);
|
||||
extern int
|
||||
Pg_lo_read(
|
||||
ClientData cData, Tcl_Interp * interp, int argc, char *argv[]);
|
||||
extern int
|
||||
Pg_lo_write(
|
||||
ClientData cData, Tcl_Interp * interp, int argc, char *argv[]);
|
||||
extern int
|
||||
Pg_lo_lseek(
|
||||
ClientData cData, Tcl_Interp * interp, int argc, char *argv[]);
|
||||
extern int
|
||||
Pg_lo_creat(
|
||||
ClientData cData, Tcl_Interp * interp, int argc, char *argv[]);
|
||||
extern int
|
||||
Pg_lo_tell(
|
||||
ClientData cData, Tcl_Interp * interp, int argc, char *argv[]);
|
||||
extern int
|
||||
Pg_lo_unlink(
|
||||
ClientData cData, Tcl_Interp * interp, int argc, char *argv[]);
|
||||
extern int
|
||||
Pg_lo_import(
|
||||
ClientData cData, Tcl_Interp * interp, int argc, char *argv[]);
|
||||
extern int
|
||||
Pg_lo_export(
|
||||
ClientData cData, Tcl_Interp * interp, int argc, char *argv[]);
|
||||
extern int
|
||||
Pg_listen(
|
||||
ClientData cData, Tcl_Interp * interp, int argc, char *argv[]);
|
||||
extern int
|
||||
Pg_notifies(
|
||||
ClientData cData, Tcl_Interp * interp, int argc, char *argv[]);
|
||||
|
||||
|
||||
#endif /*PGTCLCMDS_H*/
|
||||
|
||||
#endif /* PGTCLCMDS_H */
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* pgtclId.c--
|
||||
* useful routines to convert between strings and pointers
|
||||
* Needed because everything in tcl is a string, but we want pointers
|
||||
* to data structures
|
||||
* useful routines to convert between strings and pointers
|
||||
* Needed because everything in tcl is a string, but we want pointers
|
||||
* to data structures
|
||||
*
|
||||
* ASSUMPTION: sizeof(long) >= sizeof(void*)
|
||||
* ASSUMPTION: sizeof(long) >= sizeof(void*)
|
||||
*
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclId.c,v 1.3 1996/11/11 12:14:45 scrappy Exp $
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclId.c,v 1.4 1997/09/07 05:03:13 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -29,39 +29,40 @@
|
||||
* Create the Id for a new connection and hash it
|
||||
*/
|
||||
void
|
||||
PgSetConnectionId(Pg_clientData *cd, char *id, PGconn *conn)
|
||||
PgSetConnectionId(Pg_clientData * cd, char *id, PGconn * conn)
|
||||
{
|
||||
Tcl_HashEntry *hent;
|
||||
Pg_ConnectionId *connid;
|
||||
int hnew;
|
||||
Tcl_HashEntry *hent;
|
||||
Pg_ConnectionId *connid;
|
||||
int hnew;
|
||||
|
||||
connid = (Pg_ConnectionId *)ckalloc(sizeof(Pg_ConnectionId));
|
||||
connid->conn = conn;
|
||||
Tcl_InitHashTable(&(connid->res_hash), TCL_STRING_KEYS);
|
||||
sprintf(connid->id, "pgc%ld", cd->dbh_count++);
|
||||
strcpy(id, connid->id);
|
||||
connid = (Pg_ConnectionId *) ckalloc(sizeof(Pg_ConnectionId));
|
||||
connid->conn = conn;
|
||||
Tcl_InitHashTable(&(connid->res_hash), TCL_STRING_KEYS);
|
||||
sprintf(connid->id, "pgc%ld", cd->dbh_count++);
|
||||
strcpy(id, connid->id);
|
||||
|
||||
hent = Tcl_CreateHashEntry(&(cd->dbh_hash), connid->id, &hnew);
|
||||
Tcl_SetHashValue(hent, (ClientData)connid);
|
||||
hent = Tcl_CreateHashEntry(&(cd->dbh_hash), connid->id, &hnew);
|
||||
Tcl_SetHashValue(hent, (ClientData) connid);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Get back the connection from the Id
|
||||
*/
|
||||
PGconn *
|
||||
PgGetConnectionId(Pg_clientData *cd, char *id)
|
||||
PGconn *
|
||||
PgGetConnectionId(Pg_clientData * cd, char *id)
|
||||
{
|
||||
Tcl_HashEntry *hent;
|
||||
Pg_ConnectionId *connid;
|
||||
Tcl_HashEntry *hent;
|
||||
Pg_ConnectionId *connid;
|
||||
|
||||
hent = Tcl_FindHashEntry(&(cd->dbh_hash), id);
|
||||
if(hent == NULL) {
|
||||
return (PGconn *)NULL;
|
||||
}
|
||||
hent = Tcl_FindHashEntry(&(cd->dbh_hash), id);
|
||||
if (hent == NULL)
|
||||
{
|
||||
return (PGconn *) NULL;
|
||||
}
|
||||
|
||||
connid = (Pg_ConnectionId *)Tcl_GetHashValue(hent);
|
||||
return connid->conn;
|
||||
connid = (Pg_ConnectionId *) Tcl_GetHashValue(hent);
|
||||
return connid->conn;
|
||||
}
|
||||
|
||||
|
||||
@@ -70,36 +71,39 @@ PgGetConnectionId(Pg_clientData *cd, char *id)
|
||||
* close all portals the user forgot.
|
||||
*/
|
||||
void
|
||||
PgDelConnectionId(Pg_clientData *cd, char *id)
|
||||
PgDelConnectionId(Pg_clientData * cd, char *id)
|
||||
{
|
||||
Tcl_HashEntry *hent;
|
||||
Tcl_HashEntry *hent2;
|
||||
Tcl_HashEntry *hent3;
|
||||
Tcl_HashSearch hsearch;
|
||||
Pg_ConnectionId *connid;
|
||||
Pg_ResultId *resid;
|
||||
Tcl_HashEntry *hent;
|
||||
Tcl_HashEntry *hent2;
|
||||
Tcl_HashEntry *hent3;
|
||||
Tcl_HashSearch hsearch;
|
||||
Pg_ConnectionId *connid;
|
||||
Pg_ResultId *resid;
|
||||
|
||||
hent = Tcl_FindHashEntry(&(cd->dbh_hash), id);
|
||||
if(hent == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
connid = (Pg_ConnectionId *)Tcl_GetHashValue(hent);
|
||||
|
||||
hent2 = Tcl_FirstHashEntry(&(connid->res_hash), &hsearch);
|
||||
while(hent2 != NULL) {
|
||||
resid = (Pg_ResultId *)Tcl_GetHashValue(hent2);
|
||||
PQclear(resid->result);
|
||||
hent3 = Tcl_FindHashEntry(&(cd->res_hash), resid->id);
|
||||
if(hent3 != NULL) {
|
||||
Tcl_DeleteHashEntry(hent3);
|
||||
hent = Tcl_FindHashEntry(&(cd->dbh_hash), id);
|
||||
if (hent == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ckfree(resid);
|
||||
hent2 = Tcl_NextHashEntry(&hsearch);
|
||||
}
|
||||
Tcl_DeleteHashTable(&(connid->res_hash));
|
||||
Tcl_DeleteHashEntry(hent);
|
||||
ckfree(connid);
|
||||
|
||||
connid = (Pg_ConnectionId *) Tcl_GetHashValue(hent);
|
||||
|
||||
hent2 = Tcl_FirstHashEntry(&(connid->res_hash), &hsearch);
|
||||
while (hent2 != NULL)
|
||||
{
|
||||
resid = (Pg_ResultId *) Tcl_GetHashValue(hent2);
|
||||
PQclear(resid->result);
|
||||
hent3 = Tcl_FindHashEntry(&(cd->res_hash), resid->id);
|
||||
if (hent3 != NULL)
|
||||
{
|
||||
Tcl_DeleteHashEntry(hent3);
|
||||
}
|
||||
ckfree(resid);
|
||||
hent2 = Tcl_NextHashEntry(&hsearch);
|
||||
}
|
||||
Tcl_DeleteHashTable(&(connid->res_hash));
|
||||
Tcl_DeleteHashEntry(hent);
|
||||
ckfree(connid);
|
||||
}
|
||||
|
||||
|
||||
@@ -107,52 +111,57 @@ PgDelConnectionId(Pg_clientData *cd, char *id)
|
||||
* Create a new result Id and hash it
|
||||
*/
|
||||
void
|
||||
PgSetResultId(Pg_clientData *cd, char *id, char *connid_c, PGresult *res)
|
||||
PgSetResultId(Pg_clientData * cd, char *id, char *connid_c, PGresult * res)
|
||||
{
|
||||
Tcl_HashEntry *hent;
|
||||
Pg_ConnectionId *connid;
|
||||
Pg_ResultId *resid;
|
||||
int hnew;
|
||||
Tcl_HashEntry *hent;
|
||||
Pg_ConnectionId *connid;
|
||||
Pg_ResultId *resid;
|
||||
int hnew;
|
||||
|
||||
hent = Tcl_FindHashEntry(&(cd->dbh_hash), connid_c);
|
||||
if(hent == NULL) {
|
||||
connid = NULL;
|
||||
} else {
|
||||
connid = (Pg_ConnectionId *)Tcl_GetHashValue(hent);
|
||||
}
|
||||
hent = Tcl_FindHashEntry(&(cd->dbh_hash), connid_c);
|
||||
if (hent == NULL)
|
||||
{
|
||||
connid = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
connid = (Pg_ConnectionId *) Tcl_GetHashValue(hent);
|
||||
}
|
||||
|
||||
resid = (Pg_ResultId *)ckalloc(sizeof(Pg_ResultId));
|
||||
resid->result = res;
|
||||
resid->connection = connid;
|
||||
sprintf(resid->id, "pgr%ld", cd->res_count++);
|
||||
strcpy(id, resid->id);
|
||||
resid = (Pg_ResultId *) ckalloc(sizeof(Pg_ResultId));
|
||||
resid->result = res;
|
||||
resid->connection = connid;
|
||||
sprintf(resid->id, "pgr%ld", cd->res_count++);
|
||||
strcpy(id, resid->id);
|
||||
|
||||
hent = Tcl_CreateHashEntry(&(cd->res_hash), resid->id, &hnew);
|
||||
Tcl_SetHashValue(hent, (ClientData)resid);
|
||||
hent = Tcl_CreateHashEntry(&(cd->res_hash), resid->id, &hnew);
|
||||
Tcl_SetHashValue(hent, (ClientData) resid);
|
||||
|
||||
if(connid != NULL) {
|
||||
hent = Tcl_CreateHashEntry(&(connid->res_hash), resid->id, &hnew);
|
||||
Tcl_SetHashValue(hent, (ClientData)resid);
|
||||
}
|
||||
if (connid != NULL)
|
||||
{
|
||||
hent = Tcl_CreateHashEntry(&(connid->res_hash), resid->id, &hnew);
|
||||
Tcl_SetHashValue(hent, (ClientData) resid);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Get back the result pointer from the Id
|
||||
*/
|
||||
PGresult *
|
||||
PgGetResultId(Pg_clientData *cd, char *id)
|
||||
PGresult *
|
||||
PgGetResultId(Pg_clientData * cd, char *id)
|
||||
{
|
||||
Tcl_HashEntry *hent;
|
||||
Pg_ResultId *resid;
|
||||
Tcl_HashEntry *hent;
|
||||
Pg_ResultId *resid;
|
||||
|
||||
hent = Tcl_FindHashEntry(&(cd->res_hash), id);
|
||||
if(hent == NULL) {
|
||||
return (PGresult *)NULL;
|
||||
}
|
||||
hent = Tcl_FindHashEntry(&(cd->res_hash), id);
|
||||
if (hent == NULL)
|
||||
{
|
||||
return (PGresult *) NULL;
|
||||
}
|
||||
|
||||
resid = (Pg_ResultId *)Tcl_GetHashValue(hent);
|
||||
return resid->result;
|
||||
resid = (Pg_ResultId *) Tcl_GetHashValue(hent);
|
||||
return resid->result;
|
||||
}
|
||||
|
||||
|
||||
@@ -160,27 +169,30 @@ PgGetResultId(Pg_clientData *cd, char *id)
|
||||
* Remove a result Id from the hash tables
|
||||
*/
|
||||
void
|
||||
PgDelResultId(Pg_clientData *cd, char *id)
|
||||
PgDelResultId(Pg_clientData * cd, char *id)
|
||||
{
|
||||
Tcl_HashEntry *hent;
|
||||
Tcl_HashEntry *hent2;
|
||||
Pg_ResultId *resid;
|
||||
Tcl_HashEntry *hent;
|
||||
Tcl_HashEntry *hent2;
|
||||
Pg_ResultId *resid;
|
||||
|
||||
hent = Tcl_FindHashEntry(&(cd->res_hash), id);
|
||||
if(hent == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
resid = (Pg_ResultId *)Tcl_GetHashValue(hent);
|
||||
if (resid->connection != NULL) {
|
||||
hent2 = Tcl_FindHashEntry(&(resid->connection->res_hash), id);
|
||||
if(hent2 != NULL) {
|
||||
Tcl_DeleteHashEntry(hent2);
|
||||
hent = Tcl_FindHashEntry(&(cd->res_hash), id);
|
||||
if (hent == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Tcl_DeleteHashEntry(hent);
|
||||
ckfree(resid);
|
||||
resid = (Pg_ResultId *) Tcl_GetHashValue(hent);
|
||||
if (resid->connection != NULL)
|
||||
{
|
||||
hent2 = Tcl_FindHashEntry(&(resid->connection->res_hash), id);
|
||||
if (hent2 != NULL)
|
||||
{
|
||||
Tcl_DeleteHashEntry(hent2);
|
||||
}
|
||||
}
|
||||
|
||||
Tcl_DeleteHashEntry(hent);
|
||||
ckfree(resid);
|
||||
}
|
||||
|
||||
|
||||
@@ -188,20 +200,20 @@ PgDelResultId(Pg_clientData *cd, char *id)
|
||||
* Get the connection Id from the result Id
|
||||
*/
|
||||
void
|
||||
PgGetConnByResultId(Pg_clientData *cd, char *id, char *resid_c)
|
||||
PgGetConnByResultId(Pg_clientData * cd, char *id, char *resid_c)
|
||||
{
|
||||
Tcl_HashEntry *hent;
|
||||
Pg_ResultId *resid;
|
||||
Tcl_HashEntry *hent;
|
||||
Pg_ResultId *resid;
|
||||
|
||||
hent = Tcl_FindHashEntry(&(cd->res_hash), id);
|
||||
if(hent == NULL) {
|
||||
return;
|
||||
}
|
||||
hent = Tcl_FindHashEntry(&(cd->res_hash), id);
|
||||
if (hent == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
resid = (Pg_ResultId *)Tcl_GetHashValue(hent);
|
||||
if (resid->connection != NULL) {
|
||||
strcpy(id, resid->connection->id);
|
||||
}
|
||||
resid = (Pg_ResultId *) Tcl_GetHashValue(hent);
|
||||
if (resid->connection != NULL)
|
||||
{
|
||||
strcpy(id, resid->connection->id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* pgtclId.h--
|
||||
* useful routines to convert between strings and pointers
|
||||
* Needed because everything in tcl is a string, but often, pointers
|
||||
* to data structures are needed.
|
||||
*
|
||||
* useful routines to convert between strings and pointers
|
||||
* Needed because everything in tcl is a string, but often, pointers
|
||||
* to data structures are needed.
|
||||
*
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: pgtclId.h,v 1.2 1996/10/30 06:18:42 scrappy Exp $
|
||||
* $Id: pgtclId.h,v 1.3 1997/09/07 05:03:14 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
extern void PgSetConnectionId(Pg_clientData *cd, char *id, PGconn *conn);
|
||||
extern PGconn *PgGetConnectionId(Pg_clientData *cd, char *id);
|
||||
extern void PgDelConnectionId(Pg_clientData *cd, char *id);
|
||||
extern void PgSetResultId(Pg_clientData *cd, char *id, char *connid, PGresult *res);
|
||||
extern PGresult *PgGetResultId(Pg_clientData *cd, char *id);
|
||||
extern void PgDelResultId(Pg_clientData *cd, char *id);
|
||||
extern void PgGetConnByResultId(Pg_clientData *cd, char *id, char *resid);
|
||||
extern void PgSetConnectionId(Pg_clientData * cd, char *id, PGconn * conn);
|
||||
extern PGconn *PgGetConnectionId(Pg_clientData * cd, char *id);
|
||||
extern void PgDelConnectionId(Pg_clientData * cd, char *id);
|
||||
extern void PgSetResultId(Pg_clientData * cd, char *id, char *connid, PGresult * res);
|
||||
extern PGresult *PgGetResultId(Pg_clientData * cd, char *id);
|
||||
extern void PgDelResultId(Pg_clientData * cd, char *id);
|
||||
extern void PgGetConnByResultId(Pg_clientData * cd, char *id, char *resid);
|
||||
|
||||
@@ -1,34 +1,34 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* fe-auth.c--
|
||||
* The front-end (client) authorization routines
|
||||
* The front-end (client) authorization routines
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-auth.c,v 1.8 1997/08/12 20:16:21 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-auth.c,v 1.9 1997/09/07 05:03:17 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
* INTERFACE ROUTINES
|
||||
* frontend (client) routines:
|
||||
* fe_sendauth send authentication information
|
||||
* fe_getauthname get user's name according to the client side
|
||||
* of the authentication system
|
||||
* fe_setauthsvc set frontend authentication service
|
||||
* fe_getauthsvc get current frontend authentication service
|
||||
* frontend (client) routines:
|
||||
* fe_sendauth send authentication information
|
||||
* fe_getauthname get user's name according to the client side
|
||||
* of the authentication system
|
||||
* fe_setauthsvc set frontend authentication service
|
||||
* fe_getauthsvc get current frontend authentication service
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/param.h> /* for MAXHOSTNAMELEN on most */
|
||||
#include <sys/param.h> /* for MAXHOSTNAMELEN on most */
|
||||
#ifndef MAXHOSTNAMELEN
|
||||
#include <netdb.h> /* for MAXHOSTNAMELEN on some */
|
||||
#include <netdb.h> /* for MAXHOSTNAMELEN on some */
|
||||
#endif
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
@@ -47,12 +47,12 @@
|
||||
*----------------------------------------------------------------
|
||||
*/
|
||||
|
||||
struct authsvc {
|
||||
char name[16]; /* service nickname (for command line) */
|
||||
MsgType msgtype; /* startup packet header type */
|
||||
int allowed; /* initially allowed (before command line
|
||||
* option parsing)?
|
||||
*/
|
||||
struct authsvc
|
||||
{
|
||||
char name[16]; /* service nickname (for command line) */
|
||||
MsgType msgtype; /* startup packet header type */
|
||||
int allowed; /* initially allowed (before command line
|
||||
* option parsing)? */
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -67,24 +67,24 @@ struct authsvc {
|
||||
*/
|
||||
static struct authsvc authsvcs[] = {
|
||||
#ifdef KRB4
|
||||
{ "krb4", STARTUP_KRB4_MSG, 1 },
|
||||
{ "kerberos", STARTUP_KRB4_MSG, 1 },
|
||||
#endif /* KRB4 */
|
||||
{"krb4", STARTUP_KRB4_MSG, 1},
|
||||
{"kerberos", STARTUP_KRB4_MSG, 1},
|
||||
#endif /* KRB4 */
|
||||
#ifdef KRB5
|
||||
{ "krb5", STARTUP_KRB5_MSG, 1 },
|
||||
{ "kerberos", STARTUP_KRB5_MSG, 1 },
|
||||
#endif /* KRB5 */
|
||||
{ UNAUTHNAME, STARTUP_MSG,
|
||||
{"krb5", STARTUP_KRB5_MSG, 1},
|
||||
{"kerberos", STARTUP_KRB5_MSG, 1},
|
||||
#endif /* KRB5 */
|
||||
{UNAUTHNAME, STARTUP_MSG,
|
||||
#if defined(KRB4) || defined(KRB5)
|
||||
0
|
||||
#else /* !(KRB4 || KRB5) */
|
||||
1
|
||||
#endif /* !(KRB4 || KRB5) */
|
||||
},
|
||||
{ "password", STARTUP_PASSWORD_MSG, 0 }
|
||||
0
|
||||
#else /* !(KRB4 || KRB5) */
|
||||
1
|
||||
#endif /* !(KRB4 || KRB5) */
|
||||
},
|
||||
{"password", STARTUP_PASSWORD_MSG, 0}
|
||||
};
|
||||
|
||||
static n_authsvcs = sizeof(authsvcs) / sizeof(struct authsvc);
|
||||
static n_authsvcs = sizeof(authsvcs) / sizeof(struct authsvc);
|
||||
|
||||
#ifdef KRB4
|
||||
/*----------------------------------------------------------------
|
||||
@@ -95,8 +95,8 @@ static n_authsvcs = sizeof(authsvcs) / sizeof(struct authsvc);
|
||||
#include "krb.h"
|
||||
|
||||
/* for some reason, this is not defined in krb.h ... */
|
||||
extern char *tkt_string(void);
|
||||
|
||||
extern char *tkt_string(void);
|
||||
|
||||
/*
|
||||
* pg_krb4_init -- initialization performed before any Kerberos calls are made
|
||||
*
|
||||
@@ -104,60 +104,63 @@ extern char *tkt_string(void);
|
||||
* ticket file if we want them to see a special one. (They will open the file
|
||||
* themselves.)
|
||||
*/
|
||||
static void pg_krb4_init()
|
||||
static void
|
||||
pg_krb4_init()
|
||||
{
|
||||
char *realm;
|
||||
static init_done = 0;
|
||||
|
||||
if (init_done)
|
||||
return;
|
||||
init_done = 1;
|
||||
|
||||
/*
|
||||
* If the user set PGREALM, then we use a ticket file with a special
|
||||
* name: <usual-ticket-file-name>@<PGREALM-value>
|
||||
*/
|
||||
if (realm = getenv("PGREALM")) {
|
||||
char tktbuf[MAXPATHLEN];
|
||||
|
||||
(void) sprintf(tktbuf, "%s@%s", tkt_string(), realm);
|
||||
krb_set_tkt_string(tktbuf);
|
||||
}
|
||||
char *realm;
|
||||
static init_done = 0;
|
||||
|
||||
if (init_done)
|
||||
return;
|
||||
init_done = 1;
|
||||
|
||||
/*
|
||||
* If the user set PGREALM, then we use a ticket file with a special
|
||||
* name: <usual-ticket-file-name>@<PGREALM-value>
|
||||
*/
|
||||
if (realm = getenv("PGREALM"))
|
||||
{
|
||||
char tktbuf[MAXPATHLEN];
|
||||
|
||||
(void) sprintf(tktbuf, "%s@%s", tkt_string(), realm);
|
||||
krb_set_tkt_string(tktbuf);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* pg_krb4_authname -- returns a pointer to static space containing whatever
|
||||
* name the user has authenticated to the system
|
||||
* name the user has authenticated to the system
|
||||
*
|
||||
* We obtain this information by digging around in the ticket file.
|
||||
*/
|
||||
static char *
|
||||
pg_krb4_authname(char* PQerrormsg)
|
||||
static char *
|
||||
pg_krb4_authname(char *PQerrormsg)
|
||||
{
|
||||
char instance[INST_SZ];
|
||||
char realm[REALM_SZ];
|
||||
int status;
|
||||
static char name[SNAME_SZ+1] = "";
|
||||
|
||||
if (name[0])
|
||||
return(name);
|
||||
|
||||
pg_krb4_init();
|
||||
|
||||
name[SNAME_SZ] = '\0';
|
||||
status = krb_get_tf_fullname(tkt_string(), name, instance, realm);
|
||||
if (status != KSUCCESS) {
|
||||
(void) sprintf(PQerrormsg,
|
||||
"pg_krb4_authname: krb_get_tf_fullname: %s\n",
|
||||
krb_err_txt[status]);
|
||||
return((char *) NULL);
|
||||
}
|
||||
return(name);
|
||||
char instance[INST_SZ];
|
||||
char realm[REALM_SZ];
|
||||
int status;
|
||||
static char name[SNAME_SZ + 1] = "";
|
||||
|
||||
if (name[0])
|
||||
return (name);
|
||||
|
||||
pg_krb4_init();
|
||||
|
||||
name[SNAME_SZ] = '\0';
|
||||
status = krb_get_tf_fullname(tkt_string(), name, instance, realm);
|
||||
if (status != KSUCCESS)
|
||||
{
|
||||
(void) sprintf(PQerrormsg,
|
||||
"pg_krb4_authname: krb_get_tf_fullname: %s\n",
|
||||
krb_err_txt[status]);
|
||||
return ((char *) NULL);
|
||||
}
|
||||
return (name);
|
||||
}
|
||||
|
||||
/*
|
||||
* pg_krb4_sendauth -- client routine to send authentication information to
|
||||
* the server
|
||||
* the server
|
||||
*
|
||||
* This routine does not do mutual authentication, nor does it return enough
|
||||
* information to do encrypted connections. But then, if we want to do
|
||||
@@ -170,48 +173,50 @@ pg_krb4_authname(char* PQerrormsg)
|
||||
* (canonicalized to omit all domain suffixes).
|
||||
*/
|
||||
static int
|
||||
pg_krb4_sendauth(const char* PQerrormsg, int sock,
|
||||
struct sockaddr_in *laddr,
|
||||
struct sockaddr_in *raddr,
|
||||
const char *hostname)
|
||||
pg_krb4_sendauth(const char *PQerrormsg, int sock,
|
||||
struct sockaddr_in * laddr,
|
||||
struct sockaddr_in * raddr,
|
||||
const char *hostname)
|
||||
{
|
||||
long krbopts = 0; /* one-way authentication */
|
||||
KTEXT_ST clttkt;
|
||||
int status;
|
||||
char hostbuf[MAXHOSTNAMELEN];
|
||||
const char *realm = getenv("PGREALM"); /* NULL == current realm */
|
||||
|
||||
if (!hostname || !(*hostname)) {
|
||||
if (gethostname(hostbuf, MAXHOSTNAMELEN) < 0)
|
||||
strcpy(hostbuf, "localhost");
|
||||
hostname = hostbuf;
|
||||
}
|
||||
|
||||
pg_krb4_init();
|
||||
|
||||
status = krb_sendauth(krbopts,
|
||||
sock,
|
||||
&clttkt,
|
||||
PG_KRB_SRVNAM,
|
||||
hostname,
|
||||
realm,
|
||||
(u_long) 0,
|
||||
(MSG_DAT *) NULL,
|
||||
(CREDENTIALS *) NULL,
|
||||
(Key_schedule *) NULL,
|
||||
laddr,
|
||||
raddr,
|
||||
PG_KRB4_VERSION);
|
||||
if (status != KSUCCESS) {
|
||||
(void) sprintf(PQerrormsg,
|
||||
"pg_krb4_sendauth: kerberos error: %s\n",
|
||||
krb_err_txt[status]);
|
||||
return(STATUS_ERROR);
|
||||
}
|
||||
return(STATUS_OK);
|
||||
long krbopts = 0;/* one-way authentication */
|
||||
KTEXT_ST clttkt;
|
||||
int status;
|
||||
char hostbuf[MAXHOSTNAMELEN];
|
||||
const char *realm = getenv("PGREALM"); /* NULL == current realm */
|
||||
|
||||
if (!hostname || !(*hostname))
|
||||
{
|
||||
if (gethostname(hostbuf, MAXHOSTNAMELEN) < 0)
|
||||
strcpy(hostbuf, "localhost");
|
||||
hostname = hostbuf;
|
||||
}
|
||||
|
||||
pg_krb4_init();
|
||||
|
||||
status = krb_sendauth(krbopts,
|
||||
sock,
|
||||
&clttkt,
|
||||
PG_KRB_SRVNAM,
|
||||
hostname,
|
||||
realm,
|
||||
(u_long) 0,
|
||||
(MSG_DAT *) NULL,
|
||||
(CREDENTIALS *) NULL,
|
||||
(Key_schedule *) NULL,
|
||||
laddr,
|
||||
raddr,
|
||||
PG_KRB4_VERSION);
|
||||
if (status != KSUCCESS)
|
||||
{
|
||||
(void) sprintf(PQerrormsg,
|
||||
"pg_krb4_sendauth: kerberos error: %s\n",
|
||||
krb_err_txt[status]);
|
||||
return (STATUS_ERROR);
|
||||
}
|
||||
return (STATUS_OK);
|
||||
}
|
||||
|
||||
#endif /* KRB4 */
|
||||
#endif /* KRB4 */
|
||||
|
||||
#ifdef KRB5
|
||||
/*----------------------------------------------------------------
|
||||
@@ -223,25 +228,25 @@ pg_krb4_sendauth(const char* PQerrormsg, int sock,
|
||||
|
||||
/*
|
||||
* pg_an_to_ln -- return the local name corresponding to an authentication
|
||||
* name
|
||||
* name
|
||||
*
|
||||
* XXX Assumes that the first aname component is the user name. This is NOT
|
||||
* necessarily so, since an aname can actually be something out of your
|
||||
* worst X.400 nightmare, like
|
||||
* ORGANIZATION=U. C. Berkeley/NAME=Paul M. Aoki@CS.BERKELEY.EDU
|
||||
* Note that the MIT an_to_ln code does the same thing if you don't
|
||||
* provide an aname mapping database...it may be a better idea to use
|
||||
* krb5_an_to_ln, except that it punts if multiple components are found,
|
||||
* and we can't afford to punt.
|
||||
* necessarily so, since an aname can actually be something out of your
|
||||
* worst X.400 nightmare, like
|
||||
* ORGANIZATION=U. C. Berkeley/NAME=Paul M. Aoki@CS.BERKELEY.EDU
|
||||
* Note that the MIT an_to_ln code does the same thing if you don't
|
||||
* provide an aname mapping database...it may be a better idea to use
|
||||
* krb5_an_to_ln, except that it punts if multiple components are found,
|
||||
* and we can't afford to punt.
|
||||
*/
|
||||
static char *
|
||||
static char *
|
||||
pg_an_to_ln(const char *aname)
|
||||
{
|
||||
char *p;
|
||||
|
||||
if ((p = strchr(aname, '/')) || (p = strchr(aname, '@')))
|
||||
*p = '\0';
|
||||
return(aname);
|
||||
char *p;
|
||||
|
||||
if ((p = strchr(aname, '/')) || (p = strchr(aname, '@')))
|
||||
*p = '\0';
|
||||
return (aname);
|
||||
}
|
||||
|
||||
|
||||
@@ -251,85 +256,92 @@ pg_an_to_ln(const char *aname)
|
||||
* With v5, we can no longer set the ticket (credential cache) file name;
|
||||
* we now have to provide a file handle for the open (well, "resolved")
|
||||
* ticket file everywhere.
|
||||
*
|
||||
*
|
||||
*/
|
||||
static int
|
||||
krb5_ccache pg_krb5_init(void)
|
||||
krb5_ccache
|
||||
pg_krb5_init(void)
|
||||
{
|
||||
krb5_error_code code;
|
||||
char *realm, *defname;
|
||||
char tktbuf[MAXPATHLEN];
|
||||
static krb5_ccache ccache = (krb5_ccache) NULL;
|
||||
|
||||
if (ccache)
|
||||
return(ccache);
|
||||
|
||||
/*
|
||||
* If the user set PGREALM, then we use a ticket file with a special
|
||||
* name: <usual-ticket-file-name>@<PGREALM-value>
|
||||
*/
|
||||
if (!(defname = krb5_cc_default_name())) {
|
||||
(void) sprintf(PQerrormsg,
|
||||
"pg_krb5_init: krb5_cc_default_name failed\n");
|
||||
return((krb5_ccache) NULL);
|
||||
}
|
||||
strcpy(tktbuf, defname);
|
||||
if (realm = getenv("PGREALM")) {
|
||||
strcat(tktbuf, "@");
|
||||
strcat(tktbuf, realm);
|
||||
}
|
||||
|
||||
if (code = krb5_cc_resolve(tktbuf, &ccache)) {
|
||||
(void) sprintf(PQerrormsg,
|
||||
"pg_krb5_init: Kerberos error %d in krb5_cc_resolve\n",
|
||||
code);
|
||||
com_err("pg_krb5_init", code, "in krb5_cc_resolve");
|
||||
return((krb5_ccache) NULL);
|
||||
}
|
||||
return(ccache);
|
||||
krb5_error_code code;
|
||||
char *realm,
|
||||
*defname;
|
||||
char tktbuf[MAXPATHLEN];
|
||||
static krb5_ccache ccache = (krb5_ccache) NULL;
|
||||
|
||||
if (ccache)
|
||||
return (ccache);
|
||||
|
||||
/*
|
||||
* If the user set PGREALM, then we use a ticket file with a special
|
||||
* name: <usual-ticket-file-name>@<PGREALM-value>
|
||||
*/
|
||||
if (!(defname = krb5_cc_default_name()))
|
||||
{
|
||||
(void) sprintf(PQerrormsg,
|
||||
"pg_krb5_init: krb5_cc_default_name failed\n");
|
||||
return ((krb5_ccache) NULL);
|
||||
}
|
||||
strcpy(tktbuf, defname);
|
||||
if (realm = getenv("PGREALM"))
|
||||
{
|
||||
strcat(tktbuf, "@");
|
||||
strcat(tktbuf, realm);
|
||||
}
|
||||
|
||||
if (code = krb5_cc_resolve(tktbuf, &ccache))
|
||||
{
|
||||
(void) sprintf(PQerrormsg,
|
||||
"pg_krb5_init: Kerberos error %d in krb5_cc_resolve\n",
|
||||
code);
|
||||
com_err("pg_krb5_init", code, "in krb5_cc_resolve");
|
||||
return ((krb5_ccache) NULL);
|
||||
}
|
||||
return (ccache);
|
||||
}
|
||||
|
||||
/*
|
||||
* pg_krb5_authname -- returns a pointer to static space containing whatever
|
||||
* name the user has authenticated to the system
|
||||
* name the user has authenticated to the system
|
||||
*
|
||||
* We obtain this information by digging around in the ticket file.
|
||||
*/
|
||||
static const char *
|
||||
pg_krb5_authname(const char* PQerrormsg)
|
||||
pg_krb5_authname(const char *PQerrormsg)
|
||||
{
|
||||
krb5_ccache ccache;
|
||||
krb5_principal principal;
|
||||
krb5_error_code code;
|
||||
static char *authname = (char *) NULL;
|
||||
|
||||
if (authname)
|
||||
return(authname);
|
||||
|
||||
ccache = pg_krb5_init(); /* don't free this */
|
||||
|
||||
if (code = krb5_cc_get_principal(ccache, &principal)) {
|
||||
(void) sprintf(PQerrormsg,
|
||||
"pg_krb5_authname: Kerberos error %d in krb5_cc_get_principal\n",
|
||||
code);
|
||||
com_err("pg_krb5_authname", code, "in krb5_cc_get_principal");
|
||||
return((char *) NULL);
|
||||
}
|
||||
if (code = krb5_unparse_name(principal, &authname)) {
|
||||
(void) sprintf(PQerrormsg,
|
||||
"pg_krb5_authname: Kerberos error %d in krb5_unparse_name\n",
|
||||
code);
|
||||
com_err("pg_krb5_authname", code, "in krb5_unparse_name");
|
||||
krb5_ccache ccache;
|
||||
krb5_principal principal;
|
||||
krb5_error_code code;
|
||||
static char *authname = (char *) NULL;
|
||||
|
||||
if (authname)
|
||||
return (authname);
|
||||
|
||||
ccache = pg_krb5_init(); /* don't free this */
|
||||
|
||||
if (code = krb5_cc_get_principal(ccache, &principal))
|
||||
{
|
||||
(void) sprintf(PQerrormsg,
|
||||
"pg_krb5_authname: Kerberos error %d in krb5_cc_get_principal\n",
|
||||
code);
|
||||
com_err("pg_krb5_authname", code, "in krb5_cc_get_principal");
|
||||
return ((char *) NULL);
|
||||
}
|
||||
if (code = krb5_unparse_name(principal, &authname))
|
||||
{
|
||||
(void) sprintf(PQerrormsg,
|
||||
"pg_krb5_authname: Kerberos error %d in krb5_unparse_name\n",
|
||||
code);
|
||||
com_err("pg_krb5_authname", code, "in krb5_unparse_name");
|
||||
krb5_free_principal(principal);
|
||||
return ((char *) NULL);
|
||||
}
|
||||
krb5_free_principal(principal);
|
||||
return((char *) NULL);
|
||||
}
|
||||
krb5_free_principal(principal);
|
||||
return(pg_an_to_ln(authname));
|
||||
return (pg_an_to_ln(authname));
|
||||
}
|
||||
|
||||
/*
|
||||
* pg_krb5_sendauth -- client routine to send authentication information to
|
||||
* the server
|
||||
* the server
|
||||
*
|
||||
* This routine does not do mutual authentication, nor does it return enough
|
||||
* information to do encrypted connections. But then, if we want to do
|
||||
@@ -337,159 +349,173 @@ pg_krb5_authname(const char* PQerrormsg)
|
||||
* anyway.
|
||||
*
|
||||
* Server hostnames are canonicalized v4-style, i.e., all domain suffixes
|
||||
* are simply chopped off. Hence, we are assuming that you've entered your
|
||||
* are simply chopped off. Hence, we are assuming that you've entered your
|
||||
* server instances as
|
||||
* <value-of-PG_KRB_SRVNAM>/<canonicalized-hostname>
|
||||
* in the PGREALM (or local) database. This is probably a bad assumption.
|
||||
* <value-of-PG_KRB_SRVNAM>/<canonicalized-hostname>
|
||||
* in the PGREALM (or local) database. This is probably a bad assumption.
|
||||
*/
|
||||
static int
|
||||
pg_krb5_sendauth(const char* PQerrormsg,int sock,
|
||||
struct sockaddr_in *laddr,
|
||||
struct sockaddr_in *raddr,
|
||||
const char *hostname)
|
||||
pg_krb5_sendauth(const char *PQerrormsg, int sock,
|
||||
struct sockaddr_in * laddr,
|
||||
struct sockaddr_in * raddr,
|
||||
const char *hostname)
|
||||
{
|
||||
char servbuf[MAXHOSTNAMELEN + 1 +
|
||||
sizeof(PG_KRB_SRVNAM)];
|
||||
const char *hostp;
|
||||
const char *realm;
|
||||
krb5_error_code code;
|
||||
krb5_principal client, server;
|
||||
krb5_ccache ccache;
|
||||
krb5_error *error = (krb5_error *) NULL;
|
||||
|
||||
ccache = pg_krb5_init(); /* don't free this */
|
||||
|
||||
/*
|
||||
* set up client -- this is easy, we can get it out of the ticket
|
||||
* file.
|
||||
*/
|
||||
if (code = krb5_cc_get_principal(ccache, &client)) {
|
||||
(void) sprintf(PQerrormsg,
|
||||
"pg_krb5_sendauth: Kerberos error %d in krb5_cc_get_principal\n",
|
||||
code);
|
||||
com_err("pg_krb5_sendauth", code, "in krb5_cc_get_principal");
|
||||
return(STATUS_ERROR);
|
||||
}
|
||||
|
||||
/*
|
||||
* set up server -- canonicalize as described above
|
||||
*/
|
||||
strcpy(servbuf, PG_KRB_SRVNAM);
|
||||
*(hostp = servbuf + (sizeof(PG_KRB_SRVNAM) - 1)) = '/';
|
||||
if (hostname || *hostname) {
|
||||
strncpy(++hostp, hostname, MAXHOSTNAMELEN);
|
||||
} else {
|
||||
if (gethostname(++hostp, MAXHOSTNAMELEN) < 0)
|
||||
strcpy(hostp, "localhost");
|
||||
}
|
||||
if (hostp = strchr(hostp, '.'))
|
||||
*hostp = '\0';
|
||||
if (realm = getenv("PGREALM")) {
|
||||
strcat(servbuf, "@");
|
||||
strcat(servbuf, realm);
|
||||
}
|
||||
if (code = krb5_parse_name(servbuf, &server)) {
|
||||
(void) sprintf(PQerrormsg,
|
||||
"pg_krb5_sendauth: Kerberos error %d in krb5_parse_name\n",
|
||||
code);
|
||||
com_err("pg_krb5_sendauth", code, "in krb5_parse_name");
|
||||
krb5_free_principal(client);
|
||||
return(STATUS_ERROR);
|
||||
}
|
||||
|
||||
/*
|
||||
* The only thing we want back from krb5_sendauth is an error status
|
||||
* and any error messages.
|
||||
*/
|
||||
if (code = krb5_sendauth((krb5_pointer) &sock,
|
||||
PG_KRB5_VERSION,
|
||||
client,
|
||||
server,
|
||||
(krb5_flags) 0,
|
||||
(krb5_checksum *) NULL,
|
||||
(krb5_creds *) NULL,
|
||||
ccache,
|
||||
(krb5_int32 *) NULL,
|
||||
(krb5_keyblock **) NULL,
|
||||
&error,
|
||||
(krb5_ap_rep_enc_part **) NULL)) {
|
||||
if ((code == KRB5_SENDAUTH_REJECTED) && error) {
|
||||
(void) sprintf(PQerrormsg,
|
||||
"pg_krb5_sendauth: authentication rejected: \"%*s\"\n",
|
||||
error->text.length, error->text.data);
|
||||
fputs(PQerrormsg, stderr);
|
||||
pqdebug("%s", PQerrormsg);
|
||||
} else {
|
||||
(void) sprintf(PQerrormsg,
|
||||
"pg_krb5_sendauth: Kerberos error %d in krb5_sendauth\n",
|
||||
code);
|
||||
com_err("pg_krb5_sendauth", code, "in krb5_sendauth");
|
||||
char servbuf[MAXHOSTNAMELEN + 1 +
|
||||
sizeof(PG_KRB_SRVNAM)];
|
||||
const char *hostp;
|
||||
const char *realm;
|
||||
krb5_error_code code;
|
||||
krb5_principal client,
|
||||
server;
|
||||
krb5_ccache ccache;
|
||||
krb5_error *error = (krb5_error *) NULL;
|
||||
|
||||
ccache = pg_krb5_init(); /* don't free this */
|
||||
|
||||
/*
|
||||
* set up client -- this is easy, we can get it out of the ticket
|
||||
* file.
|
||||
*/
|
||||
if (code = krb5_cc_get_principal(ccache, &client))
|
||||
{
|
||||
(void) sprintf(PQerrormsg,
|
||||
"pg_krb5_sendauth: Kerberos error %d in krb5_cc_get_principal\n",
|
||||
code);
|
||||
com_err("pg_krb5_sendauth", code, "in krb5_cc_get_principal");
|
||||
return (STATUS_ERROR);
|
||||
}
|
||||
}
|
||||
krb5_free_principal(client);
|
||||
krb5_free_principal(server);
|
||||
return(code ? STATUS_ERROR : STATUS_OK);
|
||||
|
||||
/*
|
||||
* set up server -- canonicalize as described above
|
||||
*/
|
||||
strcpy(servbuf, PG_KRB_SRVNAM);
|
||||
*(hostp = servbuf + (sizeof(PG_KRB_SRVNAM) - 1)) = '/';
|
||||
if (hostname || *hostname)
|
||||
{
|
||||
strncpy(++hostp, hostname, MAXHOSTNAMELEN);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (gethostname(++hostp, MAXHOSTNAMELEN) < 0)
|
||||
strcpy(hostp, "localhost");
|
||||
}
|
||||
if (hostp = strchr(hostp, '.'))
|
||||
*hostp = '\0';
|
||||
if (realm = getenv("PGREALM"))
|
||||
{
|
||||
strcat(servbuf, "@");
|
||||
strcat(servbuf, realm);
|
||||
}
|
||||
if (code = krb5_parse_name(servbuf, &server))
|
||||
{
|
||||
(void) sprintf(PQerrormsg,
|
||||
"pg_krb5_sendauth: Kerberos error %d in krb5_parse_name\n",
|
||||
code);
|
||||
com_err("pg_krb5_sendauth", code, "in krb5_parse_name");
|
||||
krb5_free_principal(client);
|
||||
return (STATUS_ERROR);
|
||||
}
|
||||
|
||||
/*
|
||||
* The only thing we want back from krb5_sendauth is an error status
|
||||
* and any error messages.
|
||||
*/
|
||||
if (code = krb5_sendauth((krb5_pointer) & sock,
|
||||
PG_KRB5_VERSION,
|
||||
client,
|
||||
server,
|
||||
(krb5_flags) 0,
|
||||
(krb5_checksum *) NULL,
|
||||
(krb5_creds *) NULL,
|
||||
ccache,
|
||||
(krb5_int32 *) NULL,
|
||||
(krb5_keyblock **) NULL,
|
||||
&error,
|
||||
(krb5_ap_rep_enc_part **) NULL))
|
||||
{
|
||||
if ((code == KRB5_SENDAUTH_REJECTED) && error)
|
||||
{
|
||||
(void) sprintf(PQerrormsg,
|
||||
"pg_krb5_sendauth: authentication rejected: \"%*s\"\n",
|
||||
error->text.length, error->text.data);
|
||||
fputs(PQerrormsg, stderr);
|
||||
pqdebug("%s", PQerrormsg);
|
||||
}
|
||||
else
|
||||
{
|
||||
(void) sprintf(PQerrormsg,
|
||||
"pg_krb5_sendauth: Kerberos error %d in krb5_sendauth\n",
|
||||
code);
|
||||
com_err("pg_krb5_sendauth", code, "in krb5_sendauth");
|
||||
}
|
||||
}
|
||||
krb5_free_principal(client);
|
||||
krb5_free_principal(server);
|
||||
return (code ? STATUS_ERROR : STATUS_OK);
|
||||
}
|
||||
|
||||
#endif /* KRB5 */
|
||||
#endif /* KRB5 */
|
||||
|
||||
static int
|
||||
pg_password_sendauth(Port *port, const char *user, const char *password)
|
||||
pg_password_sendauth(Port * port, const char *user, const char *password)
|
||||
{
|
||||
PacketBuf buf;
|
||||
char *tmp;
|
||||
PacketBuf buf;
|
||||
char *tmp;
|
||||
|
||||
buf.len = htonl(sizeof(PacketBuf));
|
||||
buf.msgtype = STARTUP_PASSWORD_MSG;
|
||||
buf.data[0] = '\0';
|
||||
buf.len = htonl(sizeof(PacketBuf));
|
||||
buf.msgtype = STARTUP_PASSWORD_MSG;
|
||||
buf.data[0] = '\0';
|
||||
|
||||
tmp = buf.data;
|
||||
strncpy(tmp, user, strlen(user)+1);
|
||||
tmp += strlen(user)+1;
|
||||
strncpy(tmp, password, strlen(password)+1);
|
||||
tmp = buf.data;
|
||||
strncpy(tmp, user, strlen(user) + 1);
|
||||
tmp += strlen(user) + 1;
|
||||
strncpy(tmp, password, strlen(password) + 1);
|
||||
|
||||
return packetSend(port, &buf, sizeof(PacketBuf), BLOCKING);
|
||||
return packetSend(port, &buf, sizeof(PacketBuf), BLOCKING);
|
||||
}
|
||||
|
||||
/*
|
||||
* fe_sendauth -- client demux routine for outgoing authentication information
|
||||
*/
|
||||
int
|
||||
fe_sendauth(MsgType msgtype, Port *port, const char *hostname,
|
||||
const char *user, const char *password, const char* PQerrormsg)
|
||||
fe_sendauth(MsgType msgtype, Port * port, const char *hostname,
|
||||
const char *user, const char *password, const char *PQerrormsg)
|
||||
{
|
||||
switch (msgtype) {
|
||||
switch (msgtype)
|
||||
{
|
||||
#ifdef KRB4
|
||||
case STARTUP_KRB4_MSG:
|
||||
if (pg_krb4_sendauth(PQerrormsg, port->sock, &port->laddr,
|
||||
&port->raddr,
|
||||
hostname) != STATUS_OK) {
|
||||
(void) sprintf(PQerrormsg,
|
||||
"fe_sendauth: krb4 authentication failed\n");
|
||||
/* fputs(PQerrormsg, stderr); */
|
||||
return(STATUS_ERROR);
|
||||
}
|
||||
break;
|
||||
case STARTUP_KRB4_MSG:
|
||||
if (pg_krb4_sendauth(PQerrormsg, port->sock, &port->laddr,
|
||||
&port->raddr,
|
||||
hostname) != STATUS_OK)
|
||||
{
|
||||
(void) sprintf(PQerrormsg,
|
||||
"fe_sendauth: krb4 authentication failed\n");
|
||||
/* fputs(PQerrormsg, stderr); */
|
||||
return (STATUS_ERROR);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
#ifdef KRB5
|
||||
case STARTUP_KRB5_MSG:
|
||||
if (pg_krb5_sendauth(PQerrormsg,port->sock, &port->laddr,
|
||||
&port->raddr,
|
||||
hostname) != STATUS_OK) {
|
||||
(void) sprintf(PQerrormsg,
|
||||
"fe_sendauth: krb5 authentication failed\n");
|
||||
return(STATUS_ERROR);
|
||||
}
|
||||
break;
|
||||
case STARTUP_KRB5_MSG:
|
||||
if (pg_krb5_sendauth(PQerrormsg, port->sock, &port->laddr,
|
||||
&port->raddr,
|
||||
hostname) != STATUS_OK)
|
||||
{
|
||||
(void) sprintf(PQerrormsg,
|
||||
"fe_sendauth: krb5 authentication failed\n");
|
||||
return (STATUS_ERROR);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
case STARTUP_MSG:
|
||||
break;
|
||||
case STARTUP_PASSWORD_MSG:
|
||||
pg_password_sendauth(port, user, password);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return(STATUS_OK);
|
||||
case STARTUP_MSG:
|
||||
break;
|
||||
case STARTUP_PASSWORD_MSG:
|
||||
pg_password_sendauth(port, user, password);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return (STATUS_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -499,74 +525,77 @@ fe_sendauth(MsgType msgtype, Port *port, const char *hostname,
|
||||
* Set/return the authentication service currently selected for use by the
|
||||
* frontend. (You can only use one in the frontend, obviously.)
|
||||
*/
|
||||
static pg_authsvc = -1;
|
||||
static pg_authsvc = -1;
|
||||
|
||||
void
|
||||
fe_setauthsvc(const char *name, char* PQerrormsg)
|
||||
fe_setauthsvc(const char *name, char *PQerrormsg)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < n_authsvcs; ++i)
|
||||
if (!strcmp(name, authsvcs[i].name)) {
|
||||
pg_authsvc = i;
|
||||
break;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < n_authsvcs; ++i)
|
||||
if (!strcmp(name, authsvcs[i].name))
|
||||
{
|
||||
pg_authsvc = i;
|
||||
break;
|
||||
}
|
||||
if (i == n_authsvcs)
|
||||
{
|
||||
(void) sprintf(PQerrormsg,
|
||||
"fe_setauthsvc: invalid name: %s, ignoring...\n",
|
||||
name);
|
||||
}
|
||||
if (i == n_authsvcs) {
|
||||
(void) sprintf(PQerrormsg,
|
||||
"fe_setauthsvc: invalid name: %s, ignoring...\n",
|
||||
name);
|
||||
}
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
MsgType
|
||||
fe_getauthsvc(char* PQerrormsg)
|
||||
fe_getauthsvc(char *PQerrormsg)
|
||||
{
|
||||
if (pg_authsvc < 0 || pg_authsvc >= n_authsvcs)
|
||||
fe_setauthsvc(DEFAULT_CLIENT_AUTHSVC,PQerrormsg);
|
||||
return(authsvcs[pg_authsvc].msgtype);
|
||||
if (pg_authsvc < 0 || pg_authsvc >= n_authsvcs)
|
||||
fe_setauthsvc(DEFAULT_CLIENT_AUTHSVC, PQerrormsg);
|
||||
return (authsvcs[pg_authsvc].msgtype);
|
||||
}
|
||||
|
||||
/*
|
||||
* fe_getauthname -- returns a pointer to dynamic space containing whatever
|
||||
* name the user has authenticated to the system
|
||||
* name the user has authenticated to the system
|
||||
* if there is an error, return the error message in PQerrormsg
|
||||
*/
|
||||
char*
|
||||
fe_getauthname(char* PQerrormsg)
|
||||
char *
|
||||
fe_getauthname(char *PQerrormsg)
|
||||
{
|
||||
char *name = (char *) NULL;
|
||||
char *authn = (char *) NULL;
|
||||
MsgType authsvc;
|
||||
|
||||
authsvc = fe_getauthsvc(PQerrormsg);
|
||||
switch ((int) authsvc) {
|
||||
char *name = (char *) NULL;
|
||||
char *authn = (char *) NULL;
|
||||
MsgType authsvc;
|
||||
|
||||
authsvc = fe_getauthsvc(PQerrormsg);
|
||||
switch ((int) authsvc)
|
||||
{
|
||||
#ifdef KRB4
|
||||
case STARTUP_KRB4_MSG:
|
||||
name = pg_krb4_authname(PQerrormsg);
|
||||
break;
|
||||
case STARTUP_KRB4_MSG:
|
||||
name = pg_krb4_authname(PQerrormsg);
|
||||
break;
|
||||
#endif
|
||||
#ifdef KRB5
|
||||
case STARTUP_KRB5_MSG:
|
||||
name = pg_krb5_authname(PQerrormsg);
|
||||
break;
|
||||
case STARTUP_KRB5_MSG:
|
||||
name = pg_krb5_authname(PQerrormsg);
|
||||
break;
|
||||
#endif
|
||||
case STARTUP_MSG:
|
||||
{
|
||||
struct passwd *pw = getpwuid(geteuid());
|
||||
if (pw) name = pw->pw_name;
|
||||
case STARTUP_MSG:
|
||||
{
|
||||
struct passwd *pw = getpwuid(geteuid());
|
||||
|
||||
if (pw)
|
||||
name = pw->pw_name;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
(void) sprintf(PQerrormsg,
|
||||
"fe_getauthname: invalid authentication system: %d\n",
|
||||
authsvc);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
(void) sprintf(PQerrormsg,
|
||||
"fe_getauthname: invalid authentication system: %d\n",
|
||||
authsvc);
|
||||
break;
|
||||
}
|
||||
|
||||
if(name && (authn = (char *) malloc(strlen(name) + 1)))
|
||||
strcpy(authn, name);
|
||||
return(authn);
|
||||
if (name && (authn = (char *) malloc(strlen(name) + 1)))
|
||||
strcpy(authn, name);
|
||||
return (authn);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* fe-auth.h
|
||||
*
|
||||
* Definitions for network authentication routines
|
||||
*
|
||||
* Definitions for network authentication routines
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: fe-auth.h,v 1.3 1997/03/12 21:23:04 scrappy Exp $
|
||||
* $Id: fe-auth.h,v 1.4 1997/09/07 05:03:21 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef FE_AUTH_H
|
||||
#define FE_AUTH_H
|
||||
#define FE_AUTH_H
|
||||
|
||||
/*----------------------------------------------------------------
|
||||
* Common routines and definitions
|
||||
@@ -19,22 +19,22 @@
|
||||
*/
|
||||
|
||||
/* what we call "no authentication system" */
|
||||
#define UNAUTHNAME "unauth"
|
||||
#define UNAUTHNAME "unauth"
|
||||
|
||||
/* what a frontend uses by default */
|
||||
#if !defined(KRB4) && !defined(KRB5)
|
||||
#define DEFAULT_CLIENT_AUTHSVC UNAUTHNAME
|
||||
#else /* KRB4 || KRB5 */
|
||||
#define DEFAULT_CLIENT_AUTHSVC "kerberos"
|
||||
#endif /* KRB4 || KRB5 */
|
||||
#define DEFAULT_CLIENT_AUTHSVC UNAUTHNAME
|
||||
#else /* KRB4 || KRB5 */
|
||||
#define DEFAULT_CLIENT_AUTHSVC "kerberos"
|
||||
#endif /* KRB4 || KRB5 */
|
||||
|
||||
extern int fe_sendauth(MsgType msgtype, Port *port, const char *hostname,
|
||||
const char *user, const char *password,
|
||||
const char* PQerromsg);
|
||||
extern void fe_setauthsvc(const char *name, char* PQerrormsg);
|
||||
extern int
|
||||
fe_sendauth(MsgType msgtype, Port * port, const char *hostname,
|
||||
const char *user, const char *password,
|
||||
const char *PQerromsg);
|
||||
extern void fe_setauthsvc(const char *name, char *PQerrormsg);
|
||||
|
||||
#define PG_KRB4_VERSION "PGVER4.1" /* at most KRB_SENDAUTH_VLEN chars */
|
||||
#define PG_KRB5_VERSION "PGVER5.1"
|
||||
|
||||
#endif /* FE_AUTH_H */
|
||||
#define PG_KRB4_VERSION "PGVER4.1" /* at most KRB_SENDAUTH_VLEN chars */
|
||||
#define PG_KRB5_VERSION "PGVER5.1"
|
||||
|
||||
#endif /* FE_AUTH_H */
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2,28 +2,28 @@
|
||||
*
|
||||
* fe-connect.h
|
||||
*
|
||||
* Definitions related to setting up a connection to the backend
|
||||
* Definitions related to setting up a connection to the backend
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: fe-connect.h,v 1.1 1997/03/16 19:06:04 scrappy Exp $
|
||||
* $Id: fe-connect.h,v 1.2 1997/09/07 05:03:26 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef FE_CONNECT_H
|
||||
#define FE_CONNECT_H
|
||||
#define FE_CONNECT_H
|
||||
|
||||
/*----------------------------------------------------------------
|
||||
* Common routines and definitions
|
||||
*----------------------------------------------------------------
|
||||
*/
|
||||
|
||||
extern int packetSend(Port *port, PacketBuf *buf, PacketLen len, bool nonBlocking);
|
||||
extern int packetSend(Port * port, PacketBuf * buf, PacketLen len, bool nonBlocking);
|
||||
|
||||
#endif /* FE_CONNECT_H */
|
||||
#endif /* FE_CONNECT_H */
|
||||
#ifndef FE_CONNECT_H
|
||||
#define FE_CONNECT_H
|
||||
|
||||
int packetSend(Port *port, PacketBuf *buf, PacketLen len, bool nonBlocking);
|
||||
int packetSend(Port * port, PacketBuf * buf, PacketLen len, bool nonBlocking);
|
||||
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,17 +1,17 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* FILE
|
||||
* fe-misc.c
|
||||
* FILE
|
||||
* fe-misc.c
|
||||
*
|
||||
* DESCRIPTION
|
||||
* miscellaneous useful functions
|
||||
* these routines are analogous to the ones in libpq/pqcomm.c
|
||||
* DESCRIPTION
|
||||
* miscellaneous useful functions
|
||||
* these routines are analogous to the ones in libpq/pqcomm.c
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.5 1997/03/16 18:51:29 scrappy Exp $
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.6 1997/09/07 05:03:35 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -29,80 +29,84 @@
|
||||
|
||||
if debug is set, also echo the character fetched
|
||||
*/
|
||||
int pqGetc(FILE* fin, FILE* debug)
|
||||
int
|
||||
pqGetc(FILE * fin, FILE * debug)
|
||||
{
|
||||
int c;
|
||||
int c;
|
||||
|
||||
c = getc(fin);
|
||||
c = getc(fin);
|
||||
|
||||
if (debug && c != EOF)
|
||||
fprintf(debug, "From backend> %c\n", c);
|
||||
|
||||
return c;
|
||||
if (debug && c != EOF)
|
||||
fprintf(debug, "From backend> %c\n", c);
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
/* pqPutnchar:
|
||||
send a string of exactly len length into stream f
|
||||
send a string of exactly len length into stream f
|
||||
|
||||
returns 1 if there was an error, 0 otherwise.
|
||||
*/
|
||||
int pqPutnchar(const char* s, int len, FILE *f, FILE *debug)
|
||||
int
|
||||
pqPutnchar(const char *s, int len, FILE * f, FILE * debug)
|
||||
{
|
||||
if (f == NULL)
|
||||
return 1;
|
||||
if (f == NULL)
|
||||
return 1;
|
||||
|
||||
if(debug)
|
||||
fprintf(debug, "To backend> %s\n", s);
|
||||
if (debug)
|
||||
fprintf(debug, "To backend> %s\n", s);
|
||||
|
||||
if(fwrite(s, 1, len, f) != len)
|
||||
return 1;
|
||||
if (fwrite(s, 1, len, f) != len)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
/* pqGetnchar:
|
||||
get a string of exactly len length from stream f
|
||||
get a string of exactly len length from stream f
|
||||
*/
|
||||
int pqGetnchar(char* s, int len, FILE *f, FILE *debug)
|
||||
int
|
||||
pqGetnchar(char *s, int len, FILE * f, FILE * debug)
|
||||
{
|
||||
int cnt;
|
||||
int cnt;
|
||||
|
||||
if (f == NULL)
|
||||
return 1;
|
||||
|
||||
cnt = fread(s, 1, len, f);
|
||||
s[cnt] = '\0';
|
||||
/* mjl: actually needs up to len+1 bytes, is this okay? XXX */
|
||||
if (f == NULL)
|
||||
return 1;
|
||||
|
||||
if (debug)
|
||||
fprintf(debug, "From backend (%d)> %s\n", len, s);
|
||||
cnt = fread(s, 1, len, f);
|
||||
s[cnt] = '\0';
|
||||
/* mjl: actually needs up to len+1 bytes, is this okay? XXX */
|
||||
|
||||
return 0;
|
||||
if (debug)
|
||||
fprintf(debug, "From backend (%d)> %s\n", len, s);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
/* pqGets:
|
||||
get a string of up to length len from stream f
|
||||
*/
|
||||
int pqGets(char* s, int len, FILE *f, FILE *debug)
|
||||
int
|
||||
pqGets(char *s, int len, FILE * f, FILE * debug)
|
||||
{
|
||||
int c;
|
||||
const char *str = s;
|
||||
int c;
|
||||
const char *str = s;
|
||||
|
||||
if (f == NULL)
|
||||
return 1;
|
||||
|
||||
while (len-- && (c = getc(f)) != EOF && c)
|
||||
*s++ = c;
|
||||
*s = '\0';
|
||||
/* mjl: actually needs up to len+1 bytes, is this okay? XXX */
|
||||
if (f == NULL)
|
||||
return 1;
|
||||
|
||||
if (debug)
|
||||
fprintf(debug, "From backend> \"%s\"\n", str);
|
||||
while (len-- && (c = getc(f)) != EOF && c)
|
||||
*s++ = c;
|
||||
*s = '\0';
|
||||
/* mjl: actually needs up to len+1 bytes, is this okay? XXX */
|
||||
|
||||
return 0;
|
||||
if (debug)
|
||||
fprintf(debug, "From backend> \"%s\"\n", str);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
@@ -111,84 +115,91 @@ int pqGets(char* s, int len, FILE *f, FILE *debug)
|
||||
for host endianness.
|
||||
returns 0 if successful, 1 otherwise
|
||||
*/
|
||||
int pqPutInt(const int integer, int bytes, FILE* f, FILE *debug)
|
||||
int
|
||||
pqPutInt(const int integer, int bytes, FILE * f, FILE * debug)
|
||||
{
|
||||
int retval = 0;
|
||||
int retval = 0;
|
||||
|
||||
switch(bytes)
|
||||
{
|
||||
case 2:
|
||||
retval = pqPutShort(integer, f);
|
||||
break;
|
||||
case 4:
|
||||
retval = pqPutLong(integer, f);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "** int size %d not supported\n", bytes);
|
||||
retval = 1;
|
||||
}
|
||||
switch (bytes)
|
||||
{
|
||||
case 2:
|
||||
retval = pqPutShort(integer, f);
|
||||
break;
|
||||
case 4:
|
||||
retval = pqPutLong(integer, f);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "** int size %d not supported\n", bytes);
|
||||
retval = 1;
|
||||
}
|
||||
|
||||
if (debug) fprintf(debug, "To backend (%d#)> %d\n", bytes, integer);
|
||||
if (debug)
|
||||
fprintf(debug, "To backend (%d#)> %d\n", bytes, integer);
|
||||
|
||||
return retval;
|
||||
return retval;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
/* pgGetInt
|
||||
/* pgGetInt
|
||||
read a 2 or 4 byte integer from the stream and swab it around
|
||||
to compensate for different endianness
|
||||
returns 0 if successful
|
||||
returns 0 if successful
|
||||
*/
|
||||
int pqGetInt(int* result, int bytes, FILE* f, FILE *debug)
|
||||
int
|
||||
pqGetInt(int *result, int bytes, FILE * f, FILE * debug)
|
||||
{
|
||||
int retval = 0;
|
||||
|
||||
switch(bytes)
|
||||
{
|
||||
case 2:
|
||||
retval = pqGetShort(result, f);
|
||||
break;
|
||||
case 4:
|
||||
retval = pqGetLong(result, f);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "** int size %d not supported\n", bytes);
|
||||
retval = 1;
|
||||
}
|
||||
int retval = 0;
|
||||
|
||||
if (debug)
|
||||
fprintf(debug,"From backend (#%d)> %d\n", bytes, *result);
|
||||
switch (bytes)
|
||||
{
|
||||
case 2:
|
||||
retval = pqGetShort(result, f);
|
||||
break;
|
||||
case 4:
|
||||
retval = pqGetLong(result, f);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "** int size %d not supported\n", bytes);
|
||||
retval = 1;
|
||||
}
|
||||
|
||||
return retval;
|
||||
if (debug)
|
||||
fprintf(debug, "From backend (#%d)> %d\n", bytes, *result);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
int pqPuts(const char* s, FILE *f, FILE *debug)
|
||||
int
|
||||
pqPuts(const char *s, FILE * f, FILE * debug)
|
||||
{
|
||||
if (f == NULL)
|
||||
return 1;
|
||||
|
||||
if (fputs(s, f) == EOF)
|
||||
return 1;
|
||||
if (f == NULL)
|
||||
return 1;
|
||||
|
||||
fputc('\0', f); /* important to send an ending \0 since backend expects it */
|
||||
fflush(f);
|
||||
if (fputs(s, f) == EOF)
|
||||
return 1;
|
||||
|
||||
if (debug) {
|
||||
fprintf(debug, "To backend> %s\n", s);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
void pqFlush(FILE *f, FILE *debug)
|
||||
{
|
||||
if (f)
|
||||
fputc('\0', f); /* important to send an ending \0 since
|
||||
* backend expects it */
|
||||
fflush(f);
|
||||
|
||||
if (debug)
|
||||
fflush(debug);
|
||||
if (debug)
|
||||
{
|
||||
fprintf(debug, "To backend> %s\n", s);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
void
|
||||
pqFlush(FILE * f, FILE * debug)
|
||||
{
|
||||
if (f)
|
||||
fflush(f);
|
||||
|
||||
if (debug)
|
||||
fflush(debug);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* libpq-fe.h--
|
||||
* This file contains definitions for structures and
|
||||
* externs for functions used by frontend postgres applications.
|
||||
* This file contains definitions for structures and
|
||||
* externs for functions used by frontend postgres applications.
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: libpq-fe.h,v 1.20 1997/08/27 09:05:24 vadim Exp $
|
||||
* $Id: libpq-fe.h,v 1.21 1997/09/07 05:03:36 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -15,41 +15,47 @@
|
||||
#define LIBPQ_FE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
/* ----------------
|
||||
* include stuff common to fe and be
|
||||
* include stuff common to fe and be
|
||||
* ----------------
|
||||
*/
|
||||
#include "postgres_ext.h"
|
||||
#include "libpq/pqcomm.h"
|
||||
#include "lib/dllist.h"
|
||||
|
||||
typedef enum {CONNECTION_OK,
|
||||
CONNECTION_BAD} ConnStatusType;
|
||||
typedef enum
|
||||
{
|
||||
CONNECTION_OK,
|
||||
CONNECTION_BAD
|
||||
} ConnStatusType;
|
||||
|
||||
typedef enum {
|
||||
PGRES_EMPTY_QUERY = 0,
|
||||
PGRES_COMMAND_OK, /* a query command that doesn't return */
|
||||
/* anything was executed properly by the backend */
|
||||
PGRES_TUPLES_OK, /* a query command that returns tuples */
|
||||
/* was executed properly by the backend, PGresult */
|
||||
/* contains the resulttuples */
|
||||
PGRES_COPY_OUT,
|
||||
PGRES_COPY_IN,
|
||||
PGRES_BAD_RESPONSE, /* an unexpected response was recv'd from the backend */
|
||||
PGRES_NONFATAL_ERROR,
|
||||
PGRES_FATAL_ERROR
|
||||
typedef enum
|
||||
{
|
||||
PGRES_EMPTY_QUERY = 0,
|
||||
PGRES_COMMAND_OK, /* a query command that doesn't return */
|
||||
/* anything was executed properly by the backend */
|
||||
PGRES_TUPLES_OK, /* a query command that returns tuples */
|
||||
/* was executed properly by the backend, PGresult */
|
||||
/* contains the resulttuples */
|
||||
PGRES_COPY_OUT,
|
||||
PGRES_COPY_IN,
|
||||
PGRES_BAD_RESPONSE, /* an unexpected response was recv'd from
|
||||
* the backend */
|
||||
PGRES_NONFATAL_ERROR,
|
||||
PGRES_FATAL_ERROR
|
||||
|
||||
} ExecStatusType;
|
||||
} ExecStatusType;
|
||||
|
||||
/* string descriptions of the ExecStatusTypes */
|
||||
extern const char* pgresStatus[];
|
||||
extern const char *pgresStatus[];
|
||||
|
||||
/*
|
||||
* POSTGRES backend dependent Constants.
|
||||
/*
|
||||
* POSTGRES backend dependent Constants.
|
||||
*/
|
||||
|
||||
/* ERROR_MSG_LENGTH should really be the same as ELOG_MAXLEN in utils/elog.h*/
|
||||
@@ -60,236 +66,273 @@ extern const char* pgresStatus[];
|
||||
|
||||
/* ----------------
|
||||
* PQArgBlock --
|
||||
* Information (pointer to array of this structure) required
|
||||
* for the PQfn() call.
|
||||
* Information (pointer to array of this structure) required
|
||||
* for the PQfn() call.
|
||||
* ----------------
|
||||
*/
|
||||
typedef struct {
|
||||
int len;
|
||||
int isint;
|
||||
union {
|
||||
int *ptr; /* can't use void (dec compiler barfs) */
|
||||
int integer;
|
||||
} u;
|
||||
} PQArgBlock;
|
||||
typedef struct
|
||||
{
|
||||
int len;
|
||||
int isint;
|
||||
union
|
||||
{
|
||||
int *ptr;/* can't use void (dec compiler barfs) */
|
||||
int integer;
|
||||
} u;
|
||||
} PQArgBlock;
|
||||
|
||||
typedef struct pgresAttDesc {
|
||||
char* name; /* type name */
|
||||
Oid adtid; /* type id */
|
||||
short adtsize; /* type size */
|
||||
} PGresAttDesc;
|
||||
typedef struct pgresAttDesc
|
||||
{
|
||||
char *name; /* type name */
|
||||
Oid adtid; /* type id */
|
||||
short adtsize;/* type size */
|
||||
} PGresAttDesc;
|
||||
|
||||
/* use char* for Attribute values,
|
||||
ASCII tuples are guaranteed to be null-terminated
|
||||
For binary tuples, the first four bytes of the value is the size,
|
||||
and the bytes afterwards are the value. The binary value is
|
||||
and the bytes afterwards are the value. The binary value is
|
||||
not guaranteed to be null-terminated. In fact, it can have embedded nulls*/
|
||||
|
||||
#define NULL_LEN (-1) /* pg_result len for NULL value */
|
||||
#define NULL_LEN (-1) /* pg_result len for NULL value */
|
||||
|
||||
typedef struct pgresAttValue {
|
||||
int len; /* length in bytes of the value */
|
||||
char *value; /* actual value */
|
||||
} PGresAttValue;
|
||||
typedef struct pgresAttValue
|
||||
{
|
||||
int len; /* length in bytes of the value */
|
||||
char *value; /* actual value */
|
||||
} PGresAttValue;
|
||||
|
||||
typedef struct pgNotify {
|
||||
char relname[NAMEDATALEN]; /* name of relation containing data */
|
||||
int be_pid; /* process id of backend */
|
||||
} PGnotify;
|
||||
typedef struct pgNotify
|
||||
{
|
||||
char relname[NAMEDATALEN]; /* name of relation
|
||||
* containing data */
|
||||
int be_pid; /* process id of backend */
|
||||
} PGnotify;
|
||||
|
||||
typedef struct pgLobjfuncs {
|
||||
Oid fn_lo_open; /* OID of backend function lo_open */
|
||||
Oid fn_lo_close; /* OID of backend function lo_close */
|
||||
Oid fn_lo_creat; /* OID of backend function lo_creat */
|
||||
Oid fn_lo_unlink; /* OID of backend function lo_unlink */
|
||||
Oid fn_lo_lseek; /* OID of backend function lo_lseek */
|
||||
Oid fn_lo_tell; /* OID of backend function lo_tell */
|
||||
Oid fn_lo_read; /* OID of backend function LOread */
|
||||
Oid fn_lo_write; /* OID of backend function LOwrite */
|
||||
} PGlobjfuncs;
|
||||
typedef struct pgLobjfuncs
|
||||
{
|
||||
Oid fn_lo_open; /* OID of backend function lo_open */
|
||||
Oid fn_lo_close; /* OID of backend function
|
||||
* lo_close */
|
||||
Oid fn_lo_creat; /* OID of backend function
|
||||
* lo_creat */
|
||||
Oid fn_lo_unlink; /* OID of backend function
|
||||
* lo_unlink */
|
||||
Oid fn_lo_lseek; /* OID of backend function
|
||||
* lo_lseek */
|
||||
Oid fn_lo_tell; /* OID of backend function lo_tell */
|
||||
Oid fn_lo_read; /* OID of backend function LOread */
|
||||
Oid fn_lo_write; /* OID of backend function LOwrite */
|
||||
} PGlobjfuncs;
|
||||
|
||||
/* PGconn encapsulates a connection to the backend */
|
||||
typedef struct pg_conn{
|
||||
char *pghost; /* the machine on which the server is running */
|
||||
char *pgtty; /* tty on which the backend messages is displayed */
|
||||
char *pgport; /* the communication port with the backend */
|
||||
char *pgoptions; /* options to start the backend with */
|
||||
char *dbName; /* database name */
|
||||
ConnStatusType status;
|
||||
char errorMessage[ERROR_MSG_LENGTH];
|
||||
/* pipes for be/fe communication */
|
||||
FILE *Pfin;
|
||||
FILE *Pfout;
|
||||
FILE *Pfdebug;
|
||||
void *port; /* really a Port* */
|
||||
int asyncNotifyWaiting;
|
||||
Dllist* notifyList;
|
||||
char *pguser; /* Postgres username of user who is connected */
|
||||
char *pgpass;
|
||||
char *pgauth;
|
||||
PGlobjfuncs *lobjfuncs; /* Backend function OID's for large object access */
|
||||
} PGconn;
|
||||
typedef struct pg_conn
|
||||
{
|
||||
char *pghost; /* the machine on which the server is
|
||||
* running */
|
||||
char *pgtty; /* tty on which the backend messages is
|
||||
* displayed */
|
||||
char *pgport; /* the communication port with the backend */
|
||||
char *pgoptions; /* options to start the backend
|
||||
* with */
|
||||
char *dbName; /* database name */
|
||||
ConnStatusType status;
|
||||
char errorMessage[ERROR_MSG_LENGTH];
|
||||
/* pipes for be/fe communication */
|
||||
FILE *Pfin;
|
||||
FILE *Pfout;
|
||||
FILE *Pfdebug;
|
||||
void *port; /* really a Port* */
|
||||
int asyncNotifyWaiting;
|
||||
Dllist *notifyList;
|
||||
char *pguser; /* Postgres username of user who is
|
||||
* connected */
|
||||
char *pgpass;
|
||||
char *pgauth;
|
||||
PGlobjfuncs *lobjfuncs; /* Backend function OID's for
|
||||
* large object access */
|
||||
} PGconn;
|
||||
|
||||
#define CMDSTATUS_LEN 40
|
||||
|
||||
/* PGresult encapsulates the result of a query */
|
||||
/* unlike the old libpq, we assume that queries only return in one group */
|
||||
typedef struct pg_result{
|
||||
int ntups;
|
||||
int numAttributes;
|
||||
PGresAttDesc *attDescs;
|
||||
PGresAttValue* *tuples; /* each PGresTuple is an array of PGresAttValue's */
|
||||
int tupArrSize; /* size of tuples array allocated */
|
||||
ExecStatusType resultStatus;
|
||||
char cmdStatus[CMDSTATUS_LEN]; /* cmd status from the last insert query*/
|
||||
int binary; /* binary tuple values if binary == 1, otherwise ASCII */
|
||||
PGconn* conn;
|
||||
} PGresult;
|
||||
typedef struct pg_result
|
||||
{
|
||||
int ntups;
|
||||
int numAttributes;
|
||||
PGresAttDesc *attDescs;
|
||||
PGresAttValue **tuples;/* each PGresTuple is an array of
|
||||
* PGresAttValue's */
|
||||
int tupArrSize; /* size of tuples array allocated */
|
||||
ExecStatusType resultStatus;
|
||||
char cmdStatus[CMDSTATUS_LEN]; /* cmd status from the
|
||||
* last insert query */
|
||||
int binary; /* binary tuple values if binary == 1,
|
||||
* otherwise ASCII */
|
||||
PGconn *conn;
|
||||
} PGresult;
|
||||
|
||||
typedef char pqbool;
|
||||
/* We can't use the conventional "bool", because we are designed to be
|
||||
included in a user's program, and user may already have that type
|
||||
defined. Pqbool, on the other hand, is unlikely to be used.
|
||||
*/
|
||||
typedef char pqbool;
|
||||
|
||||
struct _PQprintOpt {
|
||||
pqbool header; /* print output field headings and row count */
|
||||
pqbool align; /* fill align the fields */
|
||||
pqbool standard; /* old brain dead format */
|
||||
pqbool html3; /* output html tables */
|
||||
pqbool expanded; /* expand tables */
|
||||
pqbool pager; /* use pager for output if needed */
|
||||
char *fieldSep; /* field separator */
|
||||
char *tableOpt; /* insert to HTML <table ...> */
|
||||
char *caption; /* HTML <caption> */
|
||||
char **fieldName; /* null terminated array of repalcement field names */
|
||||
};
|
||||
/*
|
||||
* We can't use the conventional "bool", because we are designed to be
|
||||
* included in a user's program, and user may already have that type
|
||||
* defined. Pqbool, on the other hand, is unlikely to be used.
|
||||
*/
|
||||
|
||||
typedef struct _PQprintOpt PQprintOpt;
|
||||
struct _PQprintOpt
|
||||
{
|
||||
pqbool header; /* print output field headings and row
|
||||
* count */
|
||||
pqbool align; /* fill align the fields */
|
||||
pqbool standard; /* old brain dead format */
|
||||
pqbool html3; /* output html tables */
|
||||
pqbool expanded; /* expand tables */
|
||||
pqbool pager; /* use pager for output if needed */
|
||||
char *fieldSep; /* field separator */
|
||||
char *tableOpt; /* insert to HTML <table ...> */
|
||||
char *caption;/* HTML <caption> */
|
||||
char **fieldName; /* null terminated array of
|
||||
* repalcement field names */
|
||||
};
|
||||
|
||||
typedef struct _PQprintOpt PQprintOpt;
|
||||
|
||||
/* ----------------
|
||||
* Structure for the conninfo parameter definitions of PQconnectdb()
|
||||
* ----------------
|
||||
*/
|
||||
struct _PQconninfoOption {
|
||||
char *keyword; /* The keyword of the option */
|
||||
char *environ; /* Fallback environment variable name */
|
||||
char *compiled; /* Fallback compiled in default value */
|
||||
char *val; /* Options value */
|
||||
char *label; /* Label for field in connect dialog */
|
||||
char *dispchar; /* Character to display for this field */
|
||||
/* in a connect dialog. Values are: */
|
||||
/* "" Display entered value as is */
|
||||
/* "*" Password field - hide value */
|
||||
/* "D" Debug options - don't */
|
||||
/* create a field by default */
|
||||
int dispsize; /* Field size in characters for dialog */
|
||||
};
|
||||
struct _PQconninfoOption
|
||||
{
|
||||
char *keyword;/* The keyword of the option */
|
||||
char *environ;/* Fallback environment variable name */
|
||||
char *compiled; /* Fallback compiled in default
|
||||
* value */
|
||||
char *val; /* Options value */
|
||||
char *label; /* Label for field in connect dialog */
|
||||
char *dispchar; /* Character to display for this
|
||||
* field */
|
||||
/* in a connect dialog. Values are: */
|
||||
/* "" Display entered value as is */
|
||||
/* "*" Password field - hide value */
|
||||
/* "D" Debug options - don't */
|
||||
/* create a field by default */
|
||||
int dispsize; /* Field size in characters for
|
||||
* dialog */
|
||||
};
|
||||
|
||||
typedef struct _PQconninfoOption PQconninfoOption;
|
||||
typedef struct _PQconninfoOption PQconninfoOption;
|
||||
|
||||
/* === in fe-connect.c === */
|
||||
/* make a new client connection to the backend */
|
||||
extern PGconn* PQconnectdb(const char* conninfo);
|
||||
extern PQconninfoOption *PQconndefaults(void);
|
||||
extern PGconn* PQsetdb(const char* pghost, const char* pgport, const char* pgoptions,
|
||||
const char* pgtty, const char* dbName);
|
||||
/* close the current connection and free the PGconn data structure */
|
||||
extern void PQfinish(PGconn* conn);
|
||||
/* close the current connection and restablish a new one with the same
|
||||
parameters */
|
||||
extern void PQreset(PGconn* conn);
|
||||
/* === in fe-connect.c === */
|
||||
/* make a new client connection to the backend */
|
||||
extern PGconn *PQconnectdb(const char *conninfo);
|
||||
extern PQconninfoOption *PQconndefaults(void);
|
||||
extern PGconn *PQsetdb(const char *pghost, const char *pgport, const char *pgoptions,
|
||||
const char *pgtty, const char *dbName);
|
||||
/* close the current connection and free the PGconn data structure */
|
||||
extern void PQfinish(PGconn * conn);
|
||||
|
||||
extern char* PQdb(PGconn* conn);
|
||||
extern char* PQuser(PGconn* conn);
|
||||
extern char* PQhost(PGconn* conn);
|
||||
extern char* PQoptions(PGconn* conn);
|
||||
extern char* PQport(PGconn* conn);
|
||||
extern char* PQtty(PGconn* conn);
|
||||
extern ConnStatusType PQstatus(PGconn* conn);
|
||||
extern char* PQerrorMessage(PGconn* conn);
|
||||
extern void PQtrace(PGconn *conn, FILE* debug_port);
|
||||
extern void PQuntrace(PGconn *conn);
|
||||
/*
|
||||
* close the current connection and restablish a new one with the same
|
||||
* parameters
|
||||
*/
|
||||
extern void PQreset(PGconn * conn);
|
||||
|
||||
extern char *PQdb(PGconn * conn);
|
||||
extern char *PQuser(PGconn * conn);
|
||||
extern char *PQhost(PGconn * conn);
|
||||
extern char *PQoptions(PGconn * conn);
|
||||
extern char *PQport(PGconn * conn);
|
||||
extern char *PQtty(PGconn * conn);
|
||||
extern ConnStatusType PQstatus(PGconn * conn);
|
||||
extern char *PQerrorMessage(PGconn * conn);
|
||||
extern void PQtrace(PGconn * conn, FILE * debug_port);
|
||||
extern void PQuntrace(PGconn * conn);
|
||||
|
||||
/* === in fe-exec.c === */
|
||||
extern PGresult* PQexec(PGconn* conn, const char* query);
|
||||
extern int PQgetline(PGconn *conn, char* string, int length);
|
||||
extern int PQendcopy(PGconn *conn);
|
||||
extern void PQputline(PGconn *conn, const char* string);
|
||||
extern ExecStatusType PQresultStatus(PGresult* res);
|
||||
extern int PQntuples(PGresult *res);
|
||||
extern int PQnfields(PGresult *res);
|
||||
extern char* PQfname(PGresult *res, int field_num);
|
||||
extern int PQfnumber(PGresult *res, const char* field_name);
|
||||
extern Oid PQftype(PGresult *res, int field_num);
|
||||
extern short PQfsize(PGresult *res, int field_num);
|
||||
extern char* PQcmdStatus(PGresult *res);
|
||||
extern const char* PQoidStatus(PGresult *res);
|
||||
extern const char* PQcmdTuples(PGresult *res);
|
||||
extern char* PQgetvalue(PGresult *res, int tup_num, int field_num);
|
||||
extern int PQgetlength(PGresult *res, int tup_num, int field_num);
|
||||
extern int PQgetisnull(PGresult *res, int tup_num, int field_num);
|
||||
extern void PQclear(PGresult* res);
|
||||
extern PGresult *PQexec(PGconn * conn, const char *query);
|
||||
extern int PQgetline(PGconn * conn, char *string, int length);
|
||||
extern int PQendcopy(PGconn * conn);
|
||||
extern void PQputline(PGconn * conn, const char *string);
|
||||
extern ExecStatusType PQresultStatus(PGresult * res);
|
||||
extern int PQntuples(PGresult * res);
|
||||
extern int PQnfields(PGresult * res);
|
||||
extern char *PQfname(PGresult * res, int field_num);
|
||||
extern int PQfnumber(PGresult * res, const char *field_name);
|
||||
extern Oid PQftype(PGresult * res, int field_num);
|
||||
extern short PQfsize(PGresult * res, int field_num);
|
||||
extern char *PQcmdStatus(PGresult * res);
|
||||
extern const char *PQoidStatus(PGresult * res);
|
||||
extern const char *PQcmdTuples(PGresult * res);
|
||||
extern char *PQgetvalue(PGresult * res, int tup_num, int field_num);
|
||||
extern int PQgetlength(PGresult * res, int tup_num, int field_num);
|
||||
extern int PQgetisnull(PGresult * res, int tup_num, int field_num);
|
||||
extern void PQclear(PGresult * res);
|
||||
/* PQdisplayTuples() is a better version of PQprintTuples() */
|
||||
extern void PQdisplayTuples(PGresult *res,
|
||||
FILE *fp, /* where to send the output */
|
||||
int fillAlign, /* pad the fields with spaces */
|
||||
const char *fieldSep, /* field separator */
|
||||
int printHeader, /* display headers? */
|
||||
int quiet);
|
||||
extern void PQprintTuples(PGresult* res,
|
||||
FILE* fout, /* output stream */
|
||||
int printAttName,/* print attribute names or not*/
|
||||
int terseOutput, /* delimiter bars or not?*/
|
||||
int width /* width of column,
|
||||
if 0, use variable width */
|
||||
);
|
||||
extern void PQprint(FILE* fout, /* output stream */
|
||||
PGresult* res,
|
||||
PQprintOpt *ps /* option structure */
|
||||
);
|
||||
extern PGnotify* PQnotifies(PGconn *conn);
|
||||
extern PGresult* PQfn(PGconn* conn,
|
||||
int fnid,
|
||||
int *result_buf,
|
||||
int *result_len,
|
||||
int result_is_int,
|
||||
PQArgBlock *args,
|
||||
int nargs);
|
||||
extern void PQdisplayTuples(PGresult * res,
|
||||
FILE * fp, /* where to send the
|
||||
* output */
|
||||
int fillAlign, /* pad the fields with
|
||||
* spaces */
|
||||
const char *fieldSep, /* field separator */
|
||||
int printHeader, /* display headers? */
|
||||
int quiet);
|
||||
extern void PQprintTuples(PGresult * res,
|
||||
FILE * fout, /* output stream */
|
||||
int printAttName, /* print attribute names
|
||||
* or not */
|
||||
int terseOutput, /* delimiter bars or
|
||||
* not? */
|
||||
int width /* width of column, if
|
||||
* 0, use variable width */
|
||||
);
|
||||
extern void PQprint(FILE * fout, /* output stream */
|
||||
PGresult * res,
|
||||
PQprintOpt * ps /* option structure */
|
||||
);
|
||||
extern PGnotify *PQnotifies(PGconn * conn);
|
||||
extern PGresult *PQfn(PGconn * conn,
|
||||
int fnid,
|
||||
int *result_buf,
|
||||
int *result_len,
|
||||
int result_is_int,
|
||||
PQArgBlock * args,
|
||||
int nargs);
|
||||
/* === in fe-auth.c === */
|
||||
extern MsgType fe_getauthsvc(char* PQerrormsg);
|
||||
extern void fe_setauthsvc(const char *name, char* PQerrormsg);
|
||||
extern char *fe_getauthname(char* PQerrormsg);
|
||||
extern MsgType fe_getauthsvc(char *PQerrormsg);
|
||||
extern void fe_setauthsvc(const char *name, char *PQerrormsg);
|
||||
extern char *fe_getauthname(char *PQerrormsg);
|
||||
|
||||
/* === in fe-misc.c === */
|
||||
/* pqGets and pqPuts gets and sends strings to the file stream
|
||||
returns 0 if successful
|
||||
if debug is non-null, debugging output is sent to that stream
|
||||
returns 0 if successful
|
||||
if debug is non-null, debugging output is sent to that stream
|
||||
*/
|
||||
extern int pqGets(char* s, int maxlen, FILE* stream, FILE* debug);
|
||||
extern int pqGetnchar(char* s, int maxlen, FILE* stream, FILE* debug);
|
||||
extern int pqPutnchar(const char* s, int maxlen, FILE* stream, FILE* debug);
|
||||
extern int pqPuts(const char* s, FILE* stream, FILE* debug );
|
||||
extern int pqGetc(FILE* stream, FILE *debug);
|
||||
extern int pqGets(char *s, int maxlen, FILE * stream, FILE * debug);
|
||||
extern int pqGetnchar(char *s, int maxlen, FILE * stream, FILE * debug);
|
||||
extern int pqPutnchar(const char *s, int maxlen, FILE * stream, FILE * debug);
|
||||
extern int pqPuts(const char *s, FILE * stream, FILE * debug);
|
||||
extern int pqGetc(FILE * stream, FILE * debug);
|
||||
/* get a n-byte integer from the stream into result */
|
||||
/* returns 0 if successful */
|
||||
extern int pqGetInt(int* result, int bytes, FILE* stream, FILE *debug );
|
||||
extern int pqGetInt(int *result, int bytes, FILE * stream, FILE * debug);
|
||||
/* put a n-byte integer into the stream */
|
||||
/* returns 0 if successful */
|
||||
extern int pqPutInt(const int n, int bytes, FILE* stream, FILE *debug );
|
||||
extern void pqFlush(FILE* stream, FILE* debug);
|
||||
extern int pqPutInt(const int n, int bytes, FILE * stream, FILE * debug);
|
||||
extern void pqFlush(FILE * stream, FILE * debug);
|
||||
|
||||
/* === in fe-lobj.c === */
|
||||
int lo_open(PGconn* conn, Oid lobjId, int mode);
|
||||
int lo_close(PGconn *conn, int fd);
|
||||
int lo_read(PGconn *conn, int fd, char *buf, int len);
|
||||
int lo_write(PGconn *conn, int fd, char *buf, int len);
|
||||
int lo_lseek(PGconn *conn, int fd, int offset, int whence);
|
||||
Oid lo_creat(PGconn *conn, int mode);
|
||||
int lo_tell(PGconn *conn, int fd);
|
||||
int lo_unlink(PGconn *conn, Oid lobjId);
|
||||
Oid lo_import(PGconn *conn, char *filename);
|
||||
int lo_export(PGconn *conn, Oid lobjId, char *filename);
|
||||
int lo_open(PGconn * conn, Oid lobjId, int mode);
|
||||
int lo_close(PGconn * conn, int fd);
|
||||
int lo_read(PGconn * conn, int fd, char *buf, int len);
|
||||
int lo_write(PGconn * conn, int fd, char *buf, int len);
|
||||
int lo_lseek(PGconn * conn, int fd, int offset, int whence);
|
||||
Oid lo_creat(PGconn * conn, int mode);
|
||||
int lo_tell(PGconn * conn, int fd);
|
||||
int lo_unlink(PGconn * conn, Oid lobjId);
|
||||
Oid lo_import(PGconn * conn, char *filename);
|
||||
int lo_export(PGconn * conn, Oid lobjId, char *filename);
|
||||
/* max length of message to send */
|
||||
#define MAX_MESSAGE_LEN 8193
|
||||
|
||||
@@ -299,25 +342,25 @@ int lo_export(PGconn *conn, Oid lobjId, char *filename);
|
||||
|
||||
/* fall back options if they are not specified by arguments or defined
|
||||
by environment variables */
|
||||
#define DefaultHost "localhost"
|
||||
#define DefaultTty ""
|
||||
#define DefaultHost "localhost"
|
||||
#define DefaultTty ""
|
||||
#define DefaultOption ""
|
||||
#define DefaultAuthtype ""
|
||||
#define DefaultPassword ""
|
||||
#define DefaultAuthtype ""
|
||||
#define DefaultPassword ""
|
||||
|
||||
|
||||
typedef void *TUPLE;
|
||||
typedef void *TUPLE;
|
||||
#define palloc malloc
|
||||
#define pfree free
|
||||
|
||||
#if defined(sunos4)
|
||||
extern char *sys_errlist[];
|
||||
extern char *sys_errlist[];
|
||||
#define strerror(A) (sys_errlist[(A)])
|
||||
#endif /* sunos4 */
|
||||
#endif /* sunos4 */
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* LIBPQ_FE_H */
|
||||
|
||||
#endif /* LIBPQ_FE_H */
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* pqsignal.c--
|
||||
* reliable BSD-style signal(2) routine stolen from RWW who stole it
|
||||
* from Stevens...
|
||||
* reliable BSD-style signal(2) routine stolen from RWW who stole it
|
||||
* from Stevens...
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpq/pqsignal.c,v 1.3 1996/12/26 22:08:30 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpq/pqsignal.c,v 1.4 1997/09/07 05:03:37 momjian Exp $
|
||||
*
|
||||
* NOTES
|
||||
* This shouldn't be in libpq, but the monitor and some other
|
||||
* things need it...
|
||||
* This shouldn't be in libpq, but the monitor and some other
|
||||
* things need it...
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -26,18 +26,20 @@ pqsigfunc
|
||||
pqsignal(int signo, pqsigfunc func)
|
||||
{
|
||||
#if !defined(USE_POSIX_SIGNALS)
|
||||
return signal(signo, func);
|
||||
return signal(signo, func);
|
||||
#else
|
||||
struct sigaction act, oact;
|
||||
|
||||
act.sa_handler = func;
|
||||
sigemptyset(&act.sa_mask);
|
||||
act.sa_flags = 0;
|
||||
if (signo != SIGALRM) {
|
||||
act.sa_flags |= SA_RESTART;
|
||||
}
|
||||
if (sigaction(signo, &act, &oact) < 0)
|
||||
return(SIG_ERR);
|
||||
return(oact.sa_handler);
|
||||
#endif /* !USE_POSIX_SIGNALS */
|
||||
struct sigaction act,
|
||||
oact;
|
||||
|
||||
act.sa_handler = func;
|
||||
sigemptyset(&act.sa_mask);
|
||||
act.sa_flags = 0;
|
||||
if (signo != SIGALRM)
|
||||
{
|
||||
act.sa_flags |= SA_RESTART;
|
||||
}
|
||||
if (sigaction(signo, &act, &oact) < 0)
|
||||
return (SIG_ERR);
|
||||
return (oact.sa_handler);
|
||||
#endif /* !USE_POSIX_SIGNALS */
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* pqsignal.h--
|
||||
* prototypes for the reliable BSD-style signal(2) routine.
|
||||
* prototypes for the reliable BSD-style signal(2) routine.
|
||||
*
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: pqsignal.h,v 1.2 1996/12/26 22:08:34 momjian Exp $
|
||||
* $Id: pqsignal.h,v 1.3 1997/09/07 05:03:39 momjian Exp $
|
||||
*
|
||||
* NOTES
|
||||
* This shouldn't be in libpq, but the monitor and some other
|
||||
* things need it...
|
||||
* This shouldn't be in libpq, but the monitor and some other
|
||||
* things need it...
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -19,8 +19,8 @@
|
||||
|
||||
#include "c.h"
|
||||
|
||||
typedef void (*pqsigfunc)(int);
|
||||
typedef void (*pqsigfunc) (int);
|
||||
|
||||
extern pqsigfunc pqsignal(int signo, pqsigfunc func);
|
||||
|
||||
#endif /* PQSIGNAL_H */
|
||||
#endif /* PQSIGNAL_H */
|
||||
|
||||
Reference in New Issue
Block a user