NeoMutt  2024-03-23-23-gec7045
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
sasl_plain.h File Reference

SASL plain authentication support. More...

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

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.
 

Detailed Description

SASL plain authentication support.

Authors
  • Pietro Cerutti
  • 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 sasl_plain.h.

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 56 of file sasl_plain.c.

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