NeoMutt  2024-04-25-92-gf10c0f
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
gsasl2.h File Reference

GNU SASL authentication support. More...

#include <gsasl.h>
+ Include dependency graph for gsasl2.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void mutt_gsasl_client_finish (Gsasl_session **sctx)
 Free a GNU SASL client.
 
int mutt_gsasl_client_new (struct Connection *conn, const char *mech, Gsasl_session **sctx)
 Create a new GNU SASL client.
 
void mutt_gsasl_cleanup (void)
 Shutdown GNU SASL library.
 
const char * mutt_gsasl_get_mech (const char *requested_mech, const char *server_mechlist)
 Pick a connection mechanism.
 

Detailed Description

GNU SASL authentication support.

Authors
  • Richard Russon

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file gsasl2.h.

Function Documentation

◆ mutt_gsasl_client_finish()

void mutt_gsasl_client_finish ( Gsasl_session **  sctx)

Free a GNU SASL client.

Parameters
sctxGNU SASL Session

Definition at line 220 of file gsasl.c.

221{
222 gsasl_finish(*sctx);
223 *sctx = NULL;
224}
+ Here is the caller graph for this function:

◆ mutt_gsasl_client_new()

int mutt_gsasl_client_new ( struct Connection conn,
const char *  mech,
Gsasl_session **  sctx 
)

Create a new GNU SASL client.

Parameters
connConnection to a server
mechMechanisms to use
sctxGNU SASL Session
Return values
0Success
-1Error

Definition at line 199 of file gsasl.c.

200{
201 if (!mutt_gsasl_init())
202 return -1;
203
204 int rc = gsasl_client_start(MuttGsaslCtx, mech, sctx);
205 if (rc != GSASL_OK)
206 {
207 *sctx = NULL;
208 mutt_debug(LL_DEBUG1, "gsasl_client_start failed (%d): %s\n", rc, gsasl_strerror(rc));
209 return -1;
210 }
211
212 gsasl_session_hook_set(*sctx, conn);
213 return 0;
214}
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
static Gsasl * MuttGsaslCtx
Global GNU SASL handle.
Definition: gsasl.c:40
static bool mutt_gsasl_init(void)
Initialise GNU SASL library.
Definition: gsasl.c:128
@ LL_DEBUG1
Log at debug level 1.
Definition: logging2.h:43
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_gsasl_cleanup()

void mutt_gsasl_cleanup ( void  )

Shutdown GNU SASL library.

Definition at line 149 of file gsasl.c.

150{
151 if (!MuttGsaslCtx)
152 return;
153
154 gsasl_done(MuttGsaslCtx);
155 MuttGsaslCtx = NULL;
156}
+ Here is the caller graph for this function:

◆ mutt_gsasl_get_mech()

const char * mutt_gsasl_get_mech ( const char *  requested_mech,
const char *  server_mechlist 
)

Pick a connection mechanism.

Parameters
requested_mechRequested mechanism
server_mechlistServer's list of mechanisms
Return values
ptrSelected mechanism string

Definition at line 164 of file gsasl.c.

165{
166 if (!mutt_gsasl_init())
167 return NULL;
168
169 /* libgsasl does not do case-independent string comparisons,
170 * and stores its methods internally in uppercase. */
171 char *uc_server_mechlist = mutt_str_dup(server_mechlist);
172 if (uc_server_mechlist)
173 mutt_str_upper(uc_server_mechlist);
174
175 char *uc_requested_mech = mutt_str_dup(requested_mech);
176 if (uc_requested_mech)
177 mutt_str_upper(uc_requested_mech);
178
179 const char *sel_mech = NULL;
180 if (uc_requested_mech)
181 sel_mech = gsasl_client_suggest_mechanism(MuttGsaslCtx, uc_requested_mech);
182 else
183 sel_mech = gsasl_client_suggest_mechanism(MuttGsaslCtx, uc_server_mechlist);
184
185 FREE(&uc_requested_mech);
186 FREE(&uc_server_mechlist);
187
188 return sel_mech;
189}
#define FREE(x)
Definition: memory.h:45
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:253
char * mutt_str_upper(char *str)
Convert all characters in the string to uppercase.
Definition: string.c:336
+ Here is the call graph for this function:
+ Here is the caller graph for this function: