49#include <gssapi/gssapi.h>
50#define gss_nt_service_name GSS_C_NT_HOSTBASED_SERVICE
52#include <gssapi/gssapi.h>
53#include <gssapi/gssapi_generic.h>
56#define GSS_AUTH_P_NONE 1
57#define GSS_AUTH_P_INTEGRITY 2
58#define GSS_AUTH_P_PRIVACY 4
67 OM_uint32 maj_stat, min_stat;
68 OM_uint32 msg_ctx = 0;
69 gss_buffer_desc status_string;
70 char buf_maj[512] = { 0 };
71 char buf_min[512] = { 0 };
75 maj_stat = gss_display_status(&min_stat, err_maj, GSS_C_GSS_CODE,
76 GSS_C_NO_OID, &msg_ctx, &status_string);
77 if (GSS_ERROR(maj_stat))
79 size_t status_len = status_string.length;
80 if (status_len >=
sizeof(buf_maj))
81 status_len =
sizeof(buf_maj) - 1;
82 strncpy(buf_maj, (
char *) status_string.value, status_len);
83 buf_maj[status_len] =
'\0';
84 gss_release_buffer(&min_stat, &status_string);
86 maj_stat = gss_display_status(&min_stat, err_min, GSS_C_MECH_CODE,
87 GSS_C_NULL_OID, &msg_ctx, &status_string);
88 if (!GSS_ERROR(maj_stat))
90 status_len = status_string.length;
91 if (status_len >=
sizeof(buf_min))
92 status_len =
sizeof(buf_min) - 1;
93 strncpy(buf_min, (
char *) status_string.value, status_len);
94 buf_min[status_len] =
'\0';
95 gss_release_buffer(&min_stat, &status_string);
97 }
while (!GSS_ERROR(maj_stat) && (msg_ctx != 0));
107 gss_buffer_desc request_buf, send_token;
108 gss_buffer_t sec_token;
109 gss_name_t target_name;
110 gss_ctx_id_t context;
112 char server_conf_flags;
115 OM_uint32 maj_stat, min_stat;
116 unsigned long buf_size;
130 request_buf.value = buf1->
data;
131 request_buf.length =
buf_len(buf1);
134 maj_stat = gss_import_name(&min_stat, &request_buf, gss_nt_service_name, &target_name);
135 if (maj_stat != GSS_S_COMPLETE)
141 else if (c_debug_level >= 2)
143 gss_display_name(&min_stat, target_name, &request_buf, &mech_name);
145 gss_release_buffer(&min_stat, &request_buf);
148 sec_token = GSS_C_NO_BUFFER;
149 context = GSS_C_NO_CONTEXT;
152 maj_stat = gss_init_sec_context(&min_stat, GSS_C_NO_CREDENTIAL, &context, target_name,
153 GSS_C_NO_OID, GSS_C_MUTUAL_FLAG | GSS_C_SEQUENCE_FLAG,
154 0, GSS_C_NO_CHANNEL_BINDINGS, sec_token, NULL,
155 &send_token, (
unsigned int *) &cflags, NULL);
156 if ((maj_stat != GSS_S_COMPLETE) && (maj_stat != GSS_S_CONTINUE_NEEDED))
160 gss_release_name(&min_stat, &target_name);
181 gss_release_name(&min_stat, &target_name);
188 gss_release_buffer(&min_stat, &send_token);
192 while (maj_stat == GSS_S_CONTINUE_NEEDED)
203 gss_release_name(&min_stat, &target_name);
210 gss_release_name(&min_stat, &target_name);
213 request_buf.value = buf2->
data;
214 request_buf.length =
buf_len(buf2);
215 sec_token = &request_buf;
218 maj_stat = gss_init_sec_context(&min_stat, GSS_C_NO_CREDENTIAL, &context, target_name,
219 GSS_C_NO_OID, GSS_C_MUTUAL_FLAG | GSS_C_SEQUENCE_FLAG,
220 0, GSS_C_NO_CHANNEL_BINDINGS, sec_token, NULL,
221 &send_token, (
unsigned int *) &cflags, NULL);
222 if ((maj_stat != GSS_S_COMPLETE) && (maj_stat != GSS_S_CONTINUE_NEEDED))
226 gss_release_name(&min_stat, &target_name);
231 gss_release_buffer(&min_stat, &send_token);
236 gss_release_name(&min_stat, &target_name);
254 request_buf.value = buf2->
data;
255 request_buf.length =
buf_len(buf2);
257 maj_stat = gss_unwrap(&min_stat, context, &request_buf, &send_token, &cflags, &quality);
258 if (maj_stat != GSS_S_COMPLETE)
262 gss_release_buffer(&min_stat, &send_token);
268 server_conf_flags = ((
char *) send_token.value)[0];
272 gss_release_buffer(&min_stat, &send_token);
277 ((
char *) send_token.value)[0] =
'\0';
278 buf_size = ntohl(*((
long *) send_token.value));
279 gss_release_buffer(&min_stat, &send_token);
287 buf_size = htonl(buf_size);
293 request_buf.value = buf1->
data;
294 request_buf.length =
buf_len(buf1);
295 maj_stat = gss_wrap(&min_stat, context, 0, GSS_C_QOP_DEFAULT, &request_buf,
296 &cflags, &send_token);
297 if (maj_stat != GSS_S_COMPLETE)
322 maj_stat = gss_delete_sec_context(&min_stat, &context, &send_token);
323 if (maj_stat != GSS_S_COMPLETE)
330 gss_release_buffer(&min_stat, &send_token);
349 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.
#define GSS_AUTH_P_NONE
No protection (authentication only)
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
Privacy protection (encryption)
#define GSS_AUTH_P_INTEGRITY
Integrity protection.
size_t mutt_b64_buffer_encode(struct Buffer *buf, const char *in, size_t len)
Convert raw bytes to NUL-terminated base64 string.
int mutt_b64_buffer_decode(struct Buffer *buf, const char *in)
Convert NUL-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,...)
Imap-specific Account data.
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.
Shared constants/structs that are private to IMAP.
#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.
#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.
char * buf
Command buffer.
struct Connection * conn
Connection to IMAP server.
Container for Accounts, Notifications.
struct ConfigSubset * sub
Inherited config items.