PostgreSQL Source Code git master
Loading...
Searching...
No Matches
sasl.h
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * sasl.h
4 * Defines the SASL mechanism interface for the backend.
5 *
6 * Each SASL mechanism defines a frontend and a backend callback structure.
7 *
8 * See src/interfaces/libpq/fe-auth-sasl.h for the frontend counterpart.
9 *
10 * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
11 * Portions Copyright (c) 1994, Regents of the University of California
12 *
13 * src/include/libpq/sasl.h
14 *
15 *-------------------------------------------------------------------------
16 */
17
18#ifndef PG_SASL_H
19#define PG_SASL_H
20
21#include "lib/stringinfo.h"
22#include "libpq/libpq-be.h"
23
24/* Status codes for message exchange */
25#define PG_SASL_EXCHANGE_CONTINUE 0
26#define PG_SASL_EXCHANGE_SUCCESS 1
27#define PG_SASL_EXCHANGE_FAILURE 2
28#define PG_SASL_EXCHANGE_ABANDONED 3
29
30/*
31 * Maximum accepted size of SASL messages.
32 *
33 * The messages that the server or libpq generate are much smaller than this,
34 * but have some headroom.
35 */
36#define PG_MAX_SASL_MESSAGE_LENGTH 1024
37
38/*
39 * Backend SASL mechanism callbacks and metadata.
40 *
41 * To implement a backend mechanism, declare a pg_be_sasl_mech struct with
42 * appropriate callback implementations. Then pass the mechanism to
43 * CheckSASLAuth() during ClientAuthentication(), once the server has decided
44 * which authentication method to use.
45 */
46typedef struct pg_be_sasl_mech
47{
48 /*---------
49 * get_mechanisms()
50 *
51 * Retrieves the list of SASL mechanism names supported by this
52 * implementation.
53 *
54 * Input parameters:
55 *
56 * port: The client Port
57 *
58 * Output parameters:
59 *
60 * buf: A StringInfo buffer that the callback should populate with
61 * supported mechanism names. The names are appended into this
62 * StringInfo, each one ending with '\0' bytes.
63 *---------
64 */
66
67 /*---------
68 * init()
69 *
70 * Initializes mechanism-specific state for a connection. This callback
71 * must return a pointer to its allocated state, which will be passed
72 * as-is as the first argument to the other callbacks.
73 *
74 * Input parameters:
75 *
76 * port: The client Port.
77 *
78 * mech: The actual mechanism name in use by the client.
79 *
80 * shadow_pass: The stored secret for the role being authenticated, or
81 * NULL if one does not exist. Mechanisms that do not use
82 * shadow entries may ignore this parameter. If a
83 * mechanism uses shadow entries but shadow_pass is NULL,
84 * the implementation must continue the exchange as if the
85 * user existed and the password did not match, to avoid
86 * disclosing valid user names.
87 *---------
88 */
89 void *(*init) (Port *port, const char *mech, const char *shadow_pass);
90
91 /*---------
92 * exchange()
93 *
94 * Produces a server challenge to be sent to the client. The callback
95 * must return one of the PG_SASL_EXCHANGE_* values, depending on
96 * whether the exchange continues, has finished successfully, has
97 * failed, or was abandoned by the client.
98 *
99 * Input parameters:
100 *
101 * state: The opaque mechanism state returned by init()
102 *
103 * input: The response data sent by the client, or NULL if the
104 * mechanism is client-first but the client did not send an
105 * initial response. (This can only happen during the first
106 * message from the client.) This is guaranteed to be
107 * null-terminated for safety, but SASL allows embedded
108 * nulls in responses, so mechanisms must be careful to
109 * check inputlen.
110 *
111 * inputlen: The length of the challenge data sent by the server, or
112 * -1 if the client did not send an initial response
113 *
114 * Output parameters, to be set by the callback function:
115 *
116 * output: A palloc'd buffer containing either the server's next
117 * challenge (if PG_SASL_EXCHANGE_CONTINUE is returned) or
118 * the server's outcome data (if PG_SASL_EXCHANGE_SUCCESS is
119 * returned and the mechanism requires data to be sent during
120 * a successful outcome). The callback should set this to
121 * NULL if the exchange is over and no output should be sent,
122 * which should correspond to either PG_SASL_EXCHANGE_FAILURE,
123 * PG_SASL_EXCHANGE_ABANDONED, or a PG_SASL_EXCHANGE_SUCCESS
124 * with no outcome data.
125 *
126 * outputlen: The length of the challenge data. Ignored if *output is
127 * NULL.
128 *
129 * logdetail: Set to an optional DETAIL message to be printed to the
130 * server log, to disambiguate failure modes. (The client
131 * will only ever see the same generic authentication
132 * failure message.) Ignored if the exchange is completed
133 * with PG_SASL_EXCHANGE_SUCCESS or PG_SASL_EXCHANGE_ABANDONED.
134 *---------
135 */
136 int (*exchange) (void *state,
137 const char *input, int inputlen,
138 char **output, int *outputlen,
139 const char **logdetail);
140
141 /* The maximum size allowed for client SASLResponses. */
144
145/* Common implementation for auth.c */
146extern int CheckSASLAuth(const pg_be_sasl_mech *mech, Port *port,
147 char *shadow_pass, const char **logdetail,
148 bool *abandoned);
149
150#endif /* PG_SASL_H */
FILE * input
FILE * output
static int port
Definition pg_regress.c:117
static char buf[DEFAULT_XLOG_SEG_SIZE]
static int fb(int x)
int CheckSASLAuth(const pg_be_sasl_mech *mech, Port *port, char *shadow_pass, const char **logdetail, bool *abandoned)
Definition auth-sasl.c:50
int(* exchange)(void *state, const char *input, int inputlen, char **output, int *outputlen, const char **logdetail)
Definition sasl.h:136
void(* get_mechanisms)(Port *port, StringInfo buf)
Definition sasl.h:65
int max_message_length
Definition sasl.h:142