~ubuntu-branches/ubuntu/precise/libesmtp/precise

« back to all changes in this revision

Viewing changes to plain/client-plain.c

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy T. Bouse
  • Date: 2004-05-01 17:50:31 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040501175031-nf5hqbq6v1bjjm9a
Tags: 1.0.3-1
* New upstream release
* Patched libesmtp.h to include <sys/types.h> (Closes: #202648)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  This file is part of libESMTP, a library for submission of RFC 2822
3
 
 *  formatted electronic mail messages using the SMTP protocol described
4
 
 *  in RFC 2821.
5
 
 *
6
 
 *  Copyright (C) 2001,2002  Brian Stafford  <brian@stafford.uklinux.net>
7
 
 *
8
 
 *  This library is free software; you can redistribute it and/or
9
 
 *  modify it under the terms of the GNU Lesser General Public
10
 
 *  License as published by the Free Software Foundation; either
11
 
 *  version 2.1 of the License, or (at your option) any later version.
12
 
 *
13
 
 *  This library is distributed in the hope that it will be useful,
14
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 
 *  Lesser General Public License for more details.
17
 
 *
18
 
 *  You should have received a copy of the GNU Lesser General Public
19
 
 *  License along with this library; if not, write to the Free Software
20
 
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21
 
 */
22
 
 
23
 
#ifdef HAVE_CONFIG_H
24
 
#include <config.h>
25
 
#endif
26
 
 
27
 
#include <assert.h>
28
 
 
29
 
#include <string.h>
30
 
#include <stdlib.h>
31
 
 
32
 
#include "auth-client.h"
33
 
#include "auth-plugin.h"
34
 
 
35
 
#define NELT(x)         (sizeof x / sizeof x[0])
36
 
 
37
 
static int plain_init (void *pctx);
38
 
static void plain_destroy (void *ctx);
39
 
static const char *plain_response (void *ctx, const char *challenge, int *len,
40
 
                                   auth_interact_t interact, void *arg);
41
 
 
42
 
const struct auth_client_plugin sasl_client =
43
 
  {
44
 
  /* Plugin information */
45
 
    "PLAIN",
46
 
    "PLAIN mechanism (RFC 2595 section 6)",
47
 
  /* Plugin instance */
48
 
    plain_init,
49
 
    plain_destroy,
50
 
  /* Authentication */
51
 
    plain_response,
52
 
    AUTH_PLUGIN_PLAIN,
53
 
  /* Security Layer */
54
 
    0,
55
 
    NULL,
56
 
    NULL,
57
 
  };
58
 
 
59
 
static const struct auth_client_request client_request[] =
60
 
  {
61
 
    { "user",           AUTH_CLEARTEXT | AUTH_USER,     "User Name",    255, },
62
 
    { "passphrase",     AUTH_CLEARTEXT | AUTH_PASS,     "Pass Phrase",  255, },
63
 
  };
64
 
 
65
 
struct plain_context
66
 
  {
67
 
    int state;
68
 
    char buf[2 * 255 + 3];
69
 
  };
70
 
 
71
 
static int 
72
 
plain_init (void *pctx)
73
 
{
74
 
  struct plain_context *plain;
75
 
 
76
 
  plain = malloc (sizeof (struct plain_context));
77
 
  memset (plain, 0, sizeof (struct plain_context));
78
 
 
79
 
  *(void **) pctx = plain;
80
 
  return 1;
81
 
}
82
 
 
83
 
static void
84
 
plain_destroy (void *ctx)
85
 
{
86
 
  struct plain_context *plain = ctx;
87
 
 
88
 
  memset (plain->buf, '\0', sizeof plain->buf);
89
 
  free (plain);
90
 
}
91
 
 
92
 
static const char *
93
 
plain_response (void *ctx, const char *challenge __attribute__ ((unused)),
94
 
                int *len, auth_interact_t interact, void *arg)
95
 
{
96
 
  struct plain_context *plain = ctx;
97
 
  char *result[NELT (client_request)];
98
 
 
99
 
  switch (plain->state)
100
 
    {
101
 
    case 0:
102
 
      if (!(*interact) (client_request, result, NELT (client_request), arg))
103
 
        break;
104
 
      strcpy (plain->buf + 1, result[0]);
105
 
      strcpy (plain->buf + strlen (result[0]) + 2, result[1]);
106
 
      *len = strlen (result[0]) + strlen (result[1]) + 2;
107
 
      plain->state = -1;
108
 
      return plain->buf;
109
 
    }
110
 
  *len = 0;
111
 
  return NULL;
112
 
}
113