2
* Authentication module for the Micr$oft NTLM mechanism.
4
* This file is part of libESMTP, a library for submission of RFC 2822
5
* formatted electronic mail messages using the SMTP protocol described
8
* Copyright (C) 2002 Brian Stafford <brian@stafford.uklinux.net>
10
* This library is free software; you can redistribute it and/or
11
* modify it under the terms of the GNU Lesser General Public
12
* License as published by the Free Software Foundation; either
13
* version 2.1 of the License, or (at your option) any later version.
15
* This library is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18
* Lesser General Public License for more details.
20
* You should have received a copy of the GNU Lesser General Public
21
* License along with this library; if not, write to the Free Software
22
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24
#define _XOPEN_SOURCE 500
35
#include <sys/types.h>
37
#include "auth-client.h"
38
#include "auth-plugin.h"
40
#define NELT(x) (sizeof x / sizeof x[0])
42
static int ntlm_init (void *pctx);
43
static void ntlm_destroy (void *ctx);
44
static const char *ntlm_response (void *ctx,
45
const char *challenge, int *len,
46
auth_interact_t interact, void *arg);
48
const struct auth_client_plugin sasl_client =
50
/* Plugin information */
52
"NTLM Authentication Mechanism (Microsoft)",
65
static const struct auth_client_request client_request[] =
67
{ "domain", AUTH_CLEARTEXT | AUTH_REALM, "Domain", 0, },
68
{ "user", AUTH_CLEARTEXT | AUTH_USER, "User Name", 0, },
69
{ "passphrase", AUTH_PASS, "Pass Phrase", 0, },
75
char *result[NELT (client_request)];
81
ntlm_init (void *pctx)
83
struct ntlm_context *context;
85
context = malloc (sizeof (struct ntlm_context));
86
memset (context, 0, sizeof (struct ntlm_context));
88
*(void **) pctx = context;
93
ntlm_destroy (void *ctx)
95
struct ntlm_context *context = ctx;
97
memset (context, 0, sizeof (struct ntlm_context));
102
ntlm_response (void *ctx, const char *challenge, int *len,
103
auth_interact_t interact, void *arg)
105
struct ntlm_context *context = ctx;
106
unsigned char nonce[8];
107
unsigned char lm_resp[24], nt_resp[24];
111
switch (context->state)
113
case 0: /* build the authentication request */
115
if (!(*interact) (client_request, context->result, NELT (client_request),
118
gethostname (context->host, sizeof context->host);
119
if ((p = strchr (context->host, '.')) != NULL)
121
*len = ntlm_build_type_1 (context->buf, sizeof context->buf,
122
context->result[0], context->host);
125
case 1: /* compute a response based om the challenge */
127
if (!ntlm_parse_type_2 (challenge, *len, nonce, &domain))
129
ntlm_responses (lm_resp, nt_resp, nonce, context->result[2]);
130
*len = ntlm_build_type_3 (context->buf, sizeof context->buf,
132
context->result[0], context->result[1],