NeoMutt  2022-04-29-249-gaae397
Teaching an old dog new tricks
sasl_plain.c File Reference

SASL plain authentication support. More...

#include "config.h"
#include <stdio.h>
#include "mutt/lib.h"
#include "sasl_plain.h"
+ Include dependency graph for sasl_plain.c:

Go to the source code of this file.


size_t mutt_sasl_plain_msg (char *buf, size_t buflen, const char *cmd, const char *authz, const char *user, const char *pass)
 Construct a base64 encoded SASL PLAIN message. More...

Detailed Description

SASL plain authentication support.

  • Pietro Cerutti

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

Definition in file sasl_plain.c.

Function Documentation

◆ mutt_sasl_plain_msg()

size_t mutt_sasl_plain_msg ( char *  buf,
size_t  buflen,
const char *  cmd,
const char *  authz,
const char *  user,
const char *  pass 

Construct a base64 encoded SASL PLAIN message.

bufDestination buffer
buflenAvailable space in the destination buffer
cmdProtocol-specific string the prepend to the PLAIN message
authzAuthorization identity
userAuthentication identity (username)
Return values
>0Success, number of chars in the command string

This function can be used to build a protocol-specific SASL Response message using the PLAIN mechanism. The protocol specific command is given in the cmd parameter. The function appends a space, encodes the string derived from authz\0user\0pass using base64 encoding, and stores the result in buf. If cmd is either NULL or the empty string, the initial space is skipped.

authz, user, and pass can each be up to 255 bytes, making up for a 765 bytes string. Add the two NULL bytes in between plus one at the end and we get 768.

Definition at line 55 of file sasl_plain.c.

58 char tmp[768] = { 0 };
59 size_t len = 0;
60 size_t tmplen;
62 if (!user || (*user == '\0') || !pass || (*pass == '\0'))
63 return 0;
65 tmplen = snprintf(tmp, sizeof(tmp), "%s%c%s%c%s", NONULL(authz), '\0', user, '\0', pass);
67 if (cmd && *cmd)
68 {
69 len = snprintf(buf, buflen, "%s ", cmd);
70 }
71 len += mutt_b64_encode(tmp, tmplen, buf + len, buflen - len);
72 return len;
size_t mutt_b64_encode(const char *in, size_t inlen, char *out, size_t outlen)
Convert raw bytes to null-terminated base64 string.
Definition: base64.c:88
#define NONULL(x)
Definition: string2.h:37
+ Here is the call graph for this function:
+ Here is the caller graph for this function: