NeoMutt  2024-11-14-34-g5aaf0d
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 (struct Buffer *buf, 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 ( struct Buffer buf,
const char *  cmd,
const char *  authz,
const char *  user,
const char *  pass 
)

Construct a base64 encoded SASL PLAIN message.

Parameters
bufDestination 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.

Definition at line 50 of file sasl_plain.c.

52{
53 if (!user || (*user == '\0') || !pass || (*pass == '\0'))
54 return 0;
55
56 if (cmd && (*cmd != '\0'))
57 buf_printf(buf, "%s ", cmd);
58
59 struct Buffer *user_pass = buf_pool_get();
60 struct Buffer *encoded = buf_pool_get();
61
62 buf_printf(user_pass, "%s%c%s%c%s", NONULL(authz), '\0', user, '\0', pass);
63 mutt_b64_buffer_encode(encoded, buf_string(user_pass), buf_len(user_pass));
64 buf_addstr(buf, buf_string(encoded));
65
66 buf_pool_release(&user_pass);
67 buf_pool_release(&encoded);
68
69 return buf_len(buf);
70}
size_t mutt_b64_buffer_encode(struct Buffer *buf, const char *in, size_t len)
Convert raw bytes to null-terminated base64 string.
Definition: base64.c:198
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:161
size_t buf_len(const struct Buffer *buf)
Calculate the length of a Buffer.
Definition: buffer.c:491
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:226
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:96
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:81
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:94
#define NONULL(x)
Definition: string2.h:37
String manipulation buffer.
Definition: buffer.h:36
+ Here is the call graph for this function:
+ Here is the caller graph for this function: