libpq-be.h 3.17 KB
Newer Older
1 2
/*-------------------------------------------------------------------------
 *
3
 * libpq_be.h
4 5
 *	  This file contains definitions for structures and
 *	  externs for functions used by the POSTGRES backend.
6 7
 *
 *
8
 * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
Bruce Momjian's avatar
Add:  
Bruce Momjian committed
9
 * Portions Copyright (c) 1994, Regents of the University of California
10
 *
11
 * $Id: libpq-be.h,v 1.26 2001/11/12 04:19:15 tgl Exp $
12 13 14 15 16 17
 *
 *-------------------------------------------------------------------------
 */
#ifndef LIBPQ_BE_H
#define LIBPQ_BE_H

18
#include <sys/types.h>
Marc G. Fournier's avatar
Marc G. Fournier committed
19

20
#include "libpq/hba.h"
Bruce Momjian's avatar
Bruce Momjian committed
21
#include "libpq/pqcomm.h"
22

23 24 25 26 27
#ifdef USE_SSL
#include <openssl/ssl.h>
#include <openssl/err.h>
#endif

28 29 30

/* Protocol v0 password packet. */

31 32
typedef struct PasswordPacketV0
{
33 34 35 36 37 38 39 40
	uint32		unused;
	char		data[288];		/* User and password as strings. */
} PasswordPacketV0;


/*
 * Password packet.  The length of the password can be changed without
 * affecting anything.
41
 */
42 43 44 45

typedef struct PasswordPacket
{
	char		passwd[100];	/* The password. */
46 47 48 49 50
} PasswordPacket;


/* Error message packet. */

51 52 53
typedef struct ErrorMessagePacket
{
	char		data[1 + 100];	/* 'E' + the message. */
54 55 56 57 58
} ErrorMessagePacket;


/* Authentication request packet. */

59 60
typedef struct AuthRequestPacket
{
Bruce Momjian's avatar
Bruce Momjian committed
61
	char		data[1 + sizeof(AuthRequest) + 4];		/* 'R' + the request +
62
														 * optional salt. */
63 64
} AuthRequestPacket;

65

66
/* These are used by the packet handling routines. */
67

68 69
typedef enum
{
70 71 72 73
	Idle,
	ReadingPacketLength,
	ReadingPacket,
	WritingPacket
74
} PacketState;
75

76
typedef int (*PacketDoneProc) (void *arg, PacketLen pktlen, void *pktdata);
77

78 79 80
typedef struct Packet
{
	PacketState state;			/* What's in progress. */
81
	PacketLen	len;			/* Actual length */
82 83
	int			nrtodo;			/* Bytes still to transfer */
	char	   *ptr;			/* Buffer pointer */
84
	PacketDoneProc iodone;		/* I/O complete callback */
85
	void	   *arg;			/* Argument to callback */
86

87 88 89 90
	/*
	 * We declare the data buffer as a union of the allowed packet types,
	 * mainly to ensure that enough space is allocated for the largest
	 * one.
91
	 */
92

93 94
	union
	{
95 96
		/* These are outgoing so have no packet length prepended. */

97 98
		ErrorMessagePacket em;
		AuthRequestPacket ar;
99 100 101

		/* These are incoming and have a packet length prepended. */

102
		StartupPacket si;
103
		CancelRequestPacket canc;
104 105 106
		PasswordPacketV0 pwv0;
		PasswordPacket pw;
	}			pkt;
107 108 109 110
} Packet;


/*
111
 * This is used by the postmaster in its communication with frontends.	It is
112 113
 * contains all state information needed during this communication before the
 * backend is run.
114
 */
115 116 117 118

typedef struct Port
{
	int			sock;			/* File descriptor */
119 120 121
	Packet		pktInfo;		/* For the packet handlers */
	SockAddr	laddr;			/* local addr (us) */
	SockAddr	raddr;			/* remote addr (them) */
Bruce Momjian's avatar
Bruce Momjian committed
122
	char		md5Salt[4];		/* Password salt */
123
	char		cryptSalt[2];	/* Password salt */
124 125 126 127 128 129

	/*
	 * Information that needs to be held during the fe/be authentication
	 * handshake.
	 */

130
	ProtocolVersion proto;
131 132 133 134 135 136
	char		database[SM_DATABASE + 1];
	char		user[SM_USER + 1];
	char		options[SM_OPTIONS + 1];
	char		tty[SM_TTY + 1];
	char		auth_arg[MAX_AUTH_ARG];
	UserAuth	auth_method;
137

138 139
	/*
	 * SSL structures
140 141
	 */
#ifdef USE_SSL
142
	SSL		   *ssl;
143
#endif
144
} Port;
145

146

147 148
extern ProtocolVersion FrontendProtocol;

149
#endif   /* LIBPQ_BE_H */