NeoMutt  2024-12-12-14-g7b49f7
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
sasl_plain.c
Go to the documentation of this file.
1
30#include "config.h"
31#include "mutt/lib.h"
32#include "sasl_plain.h"
33
50size_t mutt_sasl_plain_msg(struct Buffer *buf, const char *cmd,
51 const char *authz, const char *user, const char *pass)
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
Convenience wrapper for the library headers.
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:82
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:96
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.
Definition: sasl_plain.c:50
SASL plain authentication support.
#define NONULL(x)
Definition: string2.h:37
String manipulation buffer.
Definition: buffer.h:36