NeoMutt  2021-02-05-666-ge300cd
Teaching an old dog new tricks
DOXYGEN
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.

Functions

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.

Authors
  • 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 http://www.gnu.org/licenses/.

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.

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

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.

57 {
58  char tmp[768];
59  size_t len = 0;
60  size_t tmplen;
61 
62  if (!user || (*user == '\0') || !pass || (*pass == '\0'))
63  return 0;
64 
65  tmplen = snprintf(tmp, sizeof(tmp), "%s%c%s%c%s", NONULL(authz), '\0', user, '\0', pass);
66 
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;
73 }
#define NONULL(x)
Definition: string2.h:37
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
const char * buf
Definition: sasl.c:67
+ Here is the call graph for this function:
+ Here is the caller graph for this function: