NeoMutt  2024-03-23-147-g885fbc
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 219 of file gsasl.c.

220{
221 gsasl_finish(*sctx);
222 *sctx = NULL;
223}
+ 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 198 of file gsasl.c.

199{
200 if (!mutt_gsasl_init())
201 return -1;
202
203 int rc = gsasl_client_start(MuttGsaslCtx, mech, sctx);
204 if (rc != GSASL_OK)
205 {
206 *sctx = NULL;
207 mutt_debug(LL_DEBUG1, "gsasl_client_start failed (%d): %s\n", rc, gsasl_strerror(rc));
208 return -1;
209 }
210
211 gsasl_session_hook_set(*sctx, conn);
212 return 0;
213}
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
static Gsasl * MuttGsaslCtx
Global GNU SASL handle.
Definition: gsasl.c:39
static bool mutt_gsasl_init(void)
Initialise GNU SASL library.
Definition: gsasl.c:127
@ 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 148 of file gsasl.c.

149{
150 if (!MuttGsaslCtx)
151 return;
152
153 gsasl_done(MuttGsaslCtx);
154 MuttGsaslCtx = NULL;
155}
+ 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 163 of file gsasl.c.

164{
165 if (!mutt_gsasl_init())
166 return NULL;
167
168 /* libgsasl does not do case-independent string comparisons,
169 * and stores its methods internally in uppercase. */
170 char *uc_server_mechlist = mutt_str_dup(server_mechlist);
171 if (uc_server_mechlist)
172 mutt_str_upper(uc_server_mechlist);
173
174 char *uc_requested_mech = mutt_str_dup(requested_mech);
175 if (uc_requested_mech)
176 mutt_str_upper(uc_requested_mech);
177
178 const char *sel_mech = NULL;
179 if (uc_requested_mech)
180 sel_mech = gsasl_client_suggest_mechanism(MuttGsaslCtx, uc_requested_mech);
181 else
182 sel_mech = gsasl_client_suggest_mechanism(MuttGsaslCtx, uc_server_mechlist);
183
184 FREE(&uc_requested_mech);
185 FREE(&uc_server_mechlist);
186
187 return sel_mech;
188}
#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:385
+ Here is the call graph for this function:
+ Here is the caller graph for this function: