SASL authentication support. More...
#include "config.h"
#include <stddef.h>
#include <errno.h>
#include <netdb.h>
#include <sasl/sasl.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include "mutt/lib.h"
#include "gui/lib.h"
#include "mutt.h"
#include "sasl.h"
#include "lib.h"
#include "options.h"
Go to the source code of this file.
Data Structures | |
struct | SaslSockData |
SASL authentication API. More... | |
Macros | |
#define | MUTT_SASL_MAXBUF 65536 |
#define | IP_PORT_BUFLEN 1024 |
Functions | |
bool | sasl_auth_validator (const char *authenticator) |
Validate an auth method against Cyrus SASL methods. More... | |
static int | getnameinfo_err (int ret) |
Convert a getaddrinfo() error code into an SASL error code. More... | |
static int | iptostring (const struct sockaddr *addr, socklen_t addrlen, char *out, unsigned int outlen) |
Convert IP Address to string. More... | |
static int | mutt_sasl_cb_log (void *context, int priority, const char *message) |
callback to log SASL messages More... | |
static int | mutt_sasl_start (void) |
Initialise SASL library. More... | |
static int | mutt_sasl_cb_authname (void *context, int id, const char **result, unsigned int *len) |
callback to retrieve authname or user from ConnAccount More... | |
static int | mutt_sasl_cb_pass (sasl_conn_t *conn, void *context, int id, sasl_secret_t **psecret) |
SASL callback function to get password. More... | |
static sasl_callback_t * | mutt_sasl_get_callbacks (struct ConnAccount *cac) |
Get the SASL callback functions. More... | |
static int | mutt_sasl_conn_open (struct Connection *conn) |
empty wrapper for underlying open function - Implements Connection::open() More... | |
static int | mutt_sasl_conn_close (struct Connection *conn) |
close SASL connection - Implements Connection::close() More... | |
static int | mutt_sasl_conn_read (struct Connection *conn, char *buf, size_t count) |
Read data from an SASL connection - Implements Connection::read() More... | |
static int | mutt_sasl_conn_write (struct Connection *conn, const char *buf, size_t count) |
Write to an SASL connection - Implements Connection::write() More... | |
static int | mutt_sasl_conn_poll (struct Connection *conn, time_t wait_secs) |
Check an SASL connection for data - Implements Connection::poll() More... | |
int | mutt_sasl_client_new (struct Connection *conn, sasl_conn_t **saslconn) |
Wrapper for sasl_client_new() More... | |
int | mutt_sasl_interact (sasl_interact_t *interaction) |
Perform an SASL interaction with the user. More... | |
void | mutt_sasl_setup_conn (struct Connection *conn, sasl_conn_t *saslconn) |
Set up an SASL connection. More... | |
void | mutt_sasl_done (void) |
Invoke when processing is complete. More... | |
Variables | |
static const char *const | sasl_authenticators [] |
Authenticaion methods supported by Cyrus SASL. More... | |
static sasl_callback_t | MuttSaslCallbacks [5] |
static sasl_secret_t * | secret_ptr = NULL |
SASL authentication support.
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 sasl.c.
bool sasl_auth_validator | ( | const char * | authenticator | ) |
Validate an auth method against Cyrus SASL methods.
authenticator | Name of the authenticator to validate |
bool | True if argument matches an accepted auth method |
Definition at line 127 of file sasl.c.
|
static |
|
static |
Convert IP Address to string.
addr | IP address |
addrlen | Size of addr struct |
out | Buffer for result |
outlen | Length of buffer |
num | SASL error code, e.g. SASL_BADPARAM |
utility function, copied from sasl2 sample code
Definition at line 206 of file sasl.c.
|
static |
|
static |
Initialise SASL library.
num | SASL error code, e.g. SASL_OK |
Call before doing an SASL exchange - initialises library (if necessary).
Definition at line 276 of file sasl.c.
|
static |
callback to retrieve authname or user from ConnAccount
[in] | context | ConnAccount |
[in] | id | Field to get. SASL_CB_USER or SASL_CB_AUTHNAME |
[out] | result | Resulting string |
[out] | len | Length of result |
num | SASL error code, e.g. SASL_FAIL |
Definition at line 316 of file sasl.c.
|
static |
SASL callback function to get password.
[in] | conn | Connection to a server |
[in] | context | ConnAccount |
[in] | id | SASL_CB_PASS |
[out] | psecret | SASL secret |
num | SASL error code, e.g SASL_FAIL |
Definition at line 360 of file sasl.c.
|
static |
Get the SASL callback functions.
cac | ConnAccount to associate with callbacks |
ptr | Array of callback functions |
Definition at line 388 of file sasl.c.
|
static |
empty wrapper for underlying open function - Implements Connection::open()
We don't know in advance that a connection will use SASL, so we replace conn's methods with sasl methods when authentication is successful, using mutt_sasl_setup_conn
Definition at line 426 of file sasl.c.
|
static |
close SASL connection - Implements Connection::close()
Calls underlying close function and disposes of the sasl_conn_t object, then restores connection to pre-sasl state
Definition at line 442 of file sasl.c.
|
static |
Read data from an SASL connection - Implements Connection::read()
Definition at line 467 of file sasl.c.
|
static |
Write to an SASL connection - Implements Connection::write()
Definition at line 531 of file sasl.c.
|
static |
Check an SASL connection for data - Implements Connection::poll()
Definition at line 581 of file sasl.c.
int mutt_sasl_client_new | ( | struct Connection * | conn, |
sasl_conn_t ** | saslconn | ||
) |
Wrapper for sasl_client_new()
[in] | conn | Connection to a server |
[out] | saslconn | SASL connection |
0 | Success |
-1 | Error |
which also sets various security properties. If this turns out to be fine for POP too we can probably stop exporting mutt_sasl_get_callbacks().
Definition at line 603 of file sasl.c.
int mutt_sasl_interact | ( | sasl_interact_t * | interaction | ) |
Perform an SASL interaction with the user.
interaction | Details of interaction |
num | SASL error code: SASL_OK or SASL_FAIL |
An example interaction might be asking the user for a password.
Definition at line 698 of file sasl.c.
void mutt_sasl_setup_conn | ( | struct Connection * | conn, |
sasl_conn_t * | saslconn | ||
) |
Set up an SASL connection.
conn | Connection to a server |
saslconn | SASL connection |
Replace connection methods, sockdata with SASL wrappers, for protection layers. Also get ssf, as a fastpath for the read/write methods.
Definition at line 731 of file sasl.c.
void mutt_sasl_done | ( | void | ) |
|
static |
Authenticaion methods supported by Cyrus SASL.