Move routines to manipulate WAL into PostgreSQL::Test::Cluster
[pgsql.git] / src / interfaces / libpq / fe-auth-sasl.h
blobf0c62139092c43fdf53fe6b180051506192201ef
1 /*-------------------------------------------------------------------------
3 * fe-auth-sasl.h
4 * Defines the SASL mechanism interface for libpq.
6 * Each SASL mechanism defines a frontend and a backend callback structure.
7 * This is not part of the public API for applications.
9 * See src/include/libpq/sasl.h for the backend counterpart.
11 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
12 * Portions Copyright (c) 1994, Regents of the University of California
14 * src/interfaces/libpq/fe-auth-sasl.h
16 *-------------------------------------------------------------------------
19 #ifndef FE_AUTH_SASL_H
20 #define FE_AUTH_SASL_H
22 #include "libpq-fe.h"
25 * Possible states for the SASL exchange, see the comment on exchange for an
26 * explanation of these.
28 typedef enum
30 SASL_COMPLETE = 0,
31 SASL_FAILED,
32 SASL_CONTINUE,
33 } SASLStatus;
36 * Frontend SASL mechanism callbacks.
38 * To implement a frontend mechanism, declare a pg_fe_sasl_mech struct with
39 * appropriate callback implementations, then hook it into conn->sasl during
40 * pg_SASL_init()'s mechanism negotiation.
42 typedef struct pg_fe_sasl_mech
44 /*-------
45 * init()
47 * Initializes mechanism-specific state for a connection. This
48 * callback must return a pointer to its allocated state, which will
49 * be passed as-is as the first argument to the other callbacks.
50 * the free() callback is called to release any state resources.
52 * If state allocation fails, the implementation should return NULL to
53 * fail the authentication exchange.
55 * Input parameters:
57 * conn: The connection to the server
59 * password: The user's supplied password for the current connection
61 * mech: The mechanism name in use, for implementations that may
62 * advertise more than one name (such as *-PLUS variants).
63 *-------
65 void *(*init) (PGconn *conn, const char *password, const char *mech);
67 /*--------
68 * exchange()
70 * Produces a client response to a server challenge. As a special case
71 * for client-first SASL mechanisms, exchange() is called with a NULL
72 * server response once at the start of the authentication exchange to
73 * generate an initial response. Returns a SASLStatus indicating the
74 * state and status of the exchange.
76 * Input parameters:
78 * state: The opaque mechanism state returned by init()
80 * input: The challenge data sent by the server, or NULL when
81 * generating a client-first initial response (that is, when
82 * the server expects the client to send a message to start
83 * the exchange). This is guaranteed to be null-terminated
84 * for safety, but SASL allows embedded nulls in challenges,
85 * so mechanisms must be careful to check inputlen.
87 * inputlen: The length of the challenge data sent by the server, or -1
88 * during client-first initial response generation.
90 * Output parameters, to be set by the callback function:
92 * output: A malloc'd buffer containing the client's response to
93 * the server (can be empty), or NULL if the exchange should
94 * be aborted. (The callback should return SASL_FAILED in the
95 * latter case.)
97 * outputlen: The length (0 or higher) of the client response buffer,
98 * ignored if output is NULL.
100 * Return value:
102 * SASL_CONTINUE: The output buffer is filled with a client response.
103 * Additional server challenge is expected
104 * SASL_COMPLETE: The SASL exchange has completed successfully.
105 * SASL_FAILED: The exchange has failed and the connection should be
106 * dropped.
107 *--------
109 SASLStatus (*exchange) (void *state, char *input, int inputlen,
110 char **output, int *outputlen);
112 /*--------
113 * channel_bound()
115 * Returns true if the connection has an established channel binding. A
116 * mechanism implementation must ensure that a SASL exchange has actually
117 * been completed, in addition to checking that channel binding is in use.
119 * Mechanisms that do not implement channel binding may simply return
120 * false.
122 * Input parameters:
124 * state: The opaque mechanism state returned by init()
125 *--------
127 bool (*channel_bound) (void *state);
129 /*--------
130 * free()
132 * Frees the state allocated by init(). This is called when the connection
133 * is dropped, not when the exchange is completed.
135 * Input parameters:
137 * state: The opaque mechanism state returned by init()
138 *--------
140 void (*free) (void *state);
142 } pg_fe_sasl_mech;
144 #endif /* FE_AUTH_SASL_H */