50#include <gssapi/gssapi.h>
51#define gss_nt_service_name GSS_C_NT_HOSTBASED_SERVICE
53#include <gssapi/gssapi.h>
54#include <gssapi/gssapi_generic.h>
57#define GSS_AUTH_P_NONE 1
58#define GSS_AUTH_P_INTEGRITY 2
59#define GSS_AUTH_P_PRIVACY 4
68 OM_uint32 maj_stat, min_stat;
69 OM_uint32 msg_ctx = 0;
70 gss_buffer_desc status_string;
71 char buf_maj[512] = { 0 };
72 char buf_min[512] = { 0 };
76 maj_stat = gss_display_status(&min_stat, err_maj, GSS_C_GSS_CODE,
77 GSS_C_NO_OID, &msg_ctx, &status_string);
78 if (GSS_ERROR(maj_stat))
80 size_t status_len = status_string.length;
81 if (status_len >=
sizeof(buf_maj))
82 status_len =
sizeof(buf_maj) - 1;
83 strncpy(buf_maj, (
char *) status_string.value, status_len);
84 buf_maj[status_len] =
'\0';
85 gss_release_buffer(&min_stat, &status_string);
87 maj_stat = gss_display_status(&min_stat, err_min, GSS_C_MECH_CODE,
88 GSS_C_NULL_OID, &msg_ctx, &status_string);
89 if (!GSS_ERROR(maj_stat))
91 status_len = status_string.length;
92 if (status_len >=
sizeof(buf_min))
93 status_len =
sizeof(buf_min) - 1;
94 strncpy(buf_min, (
char *) status_string.value, status_len);
95 buf_min[status_len] =
'\0';
96 gss_release_buffer(&min_stat, &status_string);
98 }
while (!GSS_ERROR(maj_stat) && (msg_ctx != 0));
108 gss_buffer_desc request_buf, send_token;
109 gss_buffer_t sec_token;
110 gss_name_t target_name;
111 gss_ctx_id_t context;
113 char server_conf_flags;
116 OM_uint32 maj_stat, min_stat;
117 unsigned long buf_size;
131 request_buf.value = buf1->
data;
132 request_buf.length =
buf_len(buf1);
135 maj_stat = gss_import_name(&min_stat, &request_buf, gss_nt_service_name, &target_name);
136 if (maj_stat != GSS_S_COMPLETE)
142 else if (c_debug_level >= 2)
144 gss_display_name(&min_stat, target_name, &request_buf, &mech_name);
146 gss_release_buffer(&min_stat, &request_buf);
149 sec_token = GSS_C_NO_BUFFER;
150 context = GSS_C_NO_CONTEXT;
153 maj_stat = gss_init_sec_context(&min_stat, GSS_C_NO_CREDENTIAL, &context, target_name,
154 GSS_C_NO_OID, GSS_C_MUTUAL_FLAG | GSS_C_SEQUENCE_FLAG,
155 0, GSS_C_NO_CHANNEL_BINDINGS, sec_token, NULL,
156 &send_token, (
unsigned int *) &cflags, NULL);
157 if ((maj_stat != GSS_S_COMPLETE) && (maj_stat != GSS_S_CONTINUE_NEEDED))
161 gss_release_name(&min_stat, &target_name);
182 gss_release_name(&min_stat, &target_name);
189 gss_release_buffer(&min_stat, &send_token);
193 while (maj_stat == GSS_S_CONTINUE_NEEDED)
204 gss_release_name(&min_stat, &target_name);
211 gss_release_name(&min_stat, &target_name);
214 request_buf.value = buf2->
data;
215 request_buf.length =
buf_len(buf2);
216 sec_token = &request_buf;
219 maj_stat = gss_init_sec_context(&min_stat, GSS_C_NO_CREDENTIAL, &context, target_name,
220 GSS_C_NO_OID, GSS_C_MUTUAL_FLAG | GSS_C_SEQUENCE_FLAG,
221 0, GSS_C_NO_CHANNEL_BINDINGS, sec_token, NULL,
222 &send_token, (
unsigned int *) &cflags, NULL);
223 if ((maj_stat != GSS_S_COMPLETE) && (maj_stat != GSS_S_CONTINUE_NEEDED))
227 gss_release_name(&min_stat, &target_name);
232 gss_release_buffer(&min_stat, &send_token);
237 gss_release_name(&min_stat, &target_name);
255 request_buf.value = buf2->
data;
256 request_buf.length =
buf_len(buf2);
258 maj_stat = gss_unwrap(&min_stat, context, &request_buf, &send_token, &cflags, &quality);
259 if (maj_stat != GSS_S_COMPLETE)
263 gss_release_buffer(&min_stat, &send_token);
269 server_conf_flags = ((
char *) send_token.value)[0];
273 gss_release_buffer(&min_stat, &send_token);
278 ((
char *) send_token.value)[0] =
'\0';
279 buf_size = ntohl(*((
long *) send_token.value));
280 gss_release_buffer(&min_stat, &send_token);
288 buf_size = htonl(buf_size);
294 request_buf.value = buf1->
data;
295 request_buf.length =
buf_len(buf1);
296 maj_stat = gss_wrap(&min_stat, context, 0, GSS_C_QOP_DEFAULT, &request_buf,
297 &cflags, &send_token);
298 if (maj_stat != GSS_S_COMPLETE)
323 maj_stat = gss_delete_sec_context(&min_stat, &context, &send_token);
324 if (maj_stat != GSS_S_COMPLETE)
331 gss_release_buffer(&min_stat, &send_token);
350 mutt_error(
_(
"%s authentication failed"),
"GSSAPI");
IMAP authenticator multiplexor.
ImapAuthRes
Results of IMAP Authentication.
@ IMAP_AUTH_FAILURE
Authentication failed.
@ IMAP_AUTH_SUCCESS
Authentication successful.
@ IMAP_AUTH_UNAVAIL
Authentication method not permitted.
static void print_gss_error(OM_uint32 err_maj, OM_uint32 err_min)
Print detailed error message to the debug log.
#define GSS_AUTH_P_PRIVACY
#define GSS_AUTH_P_INTEGRITY
size_t mutt_b64_buffer_encode(struct Buffer *buf, const char *in, size_t len)
Convert raw bytes to null-terminated base64 string.
int mutt_b64_buffer_decode(struct Buffer *buf, const char *in)
Convert null-terminated base64 string to raw bytes.
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
size_t buf_addstr_n(struct Buffer *buf, const char *s, size_t len)
Add a string to a Buffer, expanding it if necessary.
size_t buf_len(const struct Buffer *buf)
Calculate the length of a Buffer.
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
size_t buf_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Convenience wrapper for the config headers.
int mutt_account_getuser(struct ConnAccount *cac)
Retrieve username into ConnAccount, if necessary.
Convenience wrapper for the core headers.
enum ImapAuthRes imap_auth_gss(struct ImapAccountData *adata, const char *method)
GSS Authentication support - Implements ImapAuth::authenticate() -.
#define mutt_message(...)
#define mutt_debug(LEVEL,...)
int imap_cmd_start(struct ImapAccountData *adata, const char *cmdstr)
Given an IMAP command, send it to the server.
int imap_cmd_step(struct ImapAccountData *adata)
Reads server responses from an IMAP command.
bool imap_code(const char *s)
Was the command successful.
#define IMAP_RES_RESPOND
+
#define IMAP_CAP_AUTH_GSSAPI
RFC1731: GSSAPI authentication.
#define IMAP_RES_CONTINUE
* ...
@ LL_DEBUG2
Log at debug level 2.
@ LL_DEBUG1
Log at debug level 1.
Convenience wrapper for the library headers.
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Pop-specific Account data.
#define mutt_socket_send(conn, buf)
String manipulation buffer.
char * data
Pointer to data.
char host[128]
Server to login to.
struct ConnAccount account
Account details: username, password, etc.
IMAP-specific Account data -.
ImapCapFlags capabilities
Capability flags.
struct Connection * conn
Connection to IMAP server.
Container for Accounts, Notifications.
struct ConfigSubset * sub
Inherited config items.