~ubuntu-branches/ubuntu/trusty/postfix/trusty-proposed

« back to all changes in this revision

Viewing changes to src/lmtp/lmtp_sasl_proto.c

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2005-02-27 09:33:07 UTC
  • Revision ID: james.westby@ubuntu.com-20050227093307-cn789t27ibnlh6tf
Tags: upstream-2.1.5
ImportĀ upstreamĀ versionĀ 2.1.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*++
 
2
/* NAME
 
3
/*      lmtp_sasl_proto 3
 
4
/* SUMMARY
 
5
/*      Postfix SASL interface for LMTP client
 
6
/* SYNOPSIS
 
7
/*      #include lmtp_sasl.h
 
8
/*
 
9
/*      void    lmtp_sasl_helo_auth(state, words)
 
10
/*      LMTP_STATE *state;
 
11
/*      const char *words;
 
12
/*
 
13
/*      int     lmtp_sasl_helo_login(state)
 
14
/*      LMTP_STATE *state;
 
15
/* DESCRIPTION
 
16
/*      This module contains random chunks of code that implement
 
17
/*      the LMTP protocol interface for SASL negotiation. The goal
 
18
/*      is to reduce clutter in the main LMTP client source code.
 
19
/*
 
20
/*      lmtp_sasl_helo_auth() processes the AUTH option in the
 
21
/*      LMTP server's LHLO response.
 
22
/*
 
23
/*      lmtp_sasl_helo_login() authenticates the LMTP client to the
 
24
/*      LMTP server, using the authentication mechanism information
 
25
/*      given by the server. The result is a Postfix delivery status
 
26
/*      code in case of trouble.
 
27
/*
 
28
/*      Arguments:
 
29
/* .IP state
 
30
/*      Session context.
 
31
/* .IP words
 
32
/*      List of SASL authentication mechanisms (separated by blanks)
 
33
/* DIAGNOSTICS
 
34
/*      All errors are fatal.
 
35
/* LICENSE
 
36
/* .ad
 
37
/* .fi
 
38
/*      The Secure Mailer license must be distributed with this software.
 
39
/* AUTHOR(S)
 
40
/*      Original author:
 
41
/*      Till Franke
 
42
/*      SuSE Rhein/Main AG
 
43
/*      65760 Eschborn, Germany
 
44
/*
 
45
/*      Adopted by:
 
46
/*      Wietse Venema
 
47
/*      IBM T.J. Watson Research
 
48
/*      P.O. Box 704
 
49
/*      Yorktown Heights, NY 10598, USA
 
50
/*--*/
 
51
 
 
52
/* System library. */
 
53
 
 
54
#include <sys_defs.h>
 
55
#include <string.h>
 
56
#ifdef STRCASECMP_IN_STRINGS_H
 
57
#include <strings.h>
 
58
#endif
 
59
 
 
60
/* Utility library. */
 
61
 
 
62
#include <msg.h>
 
63
#include <mymalloc.h>
 
64
 
 
65
/* Global library. */
 
66
 
 
67
#include <mail_params.h>
 
68
 
 
69
/* Application-specific. */
 
70
 
 
71
#include "lmtp.h"
 
72
#include "lmtp_sasl.h"
 
73
 
 
74
#ifdef USE_SASL_AUTH
 
75
 
 
76
/* lmtp_sasl_helo_auth - handle AUTH option in EHLO reply */
 
77
 
 
78
void    lmtp_sasl_helo_auth(LMTP_STATE *state, const char *words)
 
79
{
 
80
 
 
81
    /*
 
82
     * XXX If the server offers a null list of authentication mechanisms,
 
83
     * then pretend that the server doesn't support SASL authentication.
 
84
     */
 
85
    if (state->sasl_mechanism_list) {
 
86
        if (strcasecmp(state->sasl_mechanism_list, words) == 0)
 
87
            return;
 
88
        myfree(state->sasl_mechanism_list);
 
89
        msg_warn("%s offered AUTH option multiple times",
 
90
                 state->session->namaddr);
 
91
        state->sasl_mechanism_list = 0;
 
92
        state->features &= ~LMTP_FEATURE_AUTH;
 
93
    }
 
94
    if (strlen(words) > 0) {
 
95
        state->sasl_mechanism_list = mystrdup(words);
 
96
        state->features |= LMTP_FEATURE_AUTH;
 
97
    } else {
 
98
        msg_warn("%s offered null AUTH mechanism list",
 
99
                 state->session->namaddr);
 
100
    }
 
101
}
 
102
 
 
103
/* lmtp_sasl_helo_login - perform SASL login */
 
104
 
 
105
int     lmtp_sasl_helo_login(LMTP_STATE *state)
 
106
{
 
107
    VSTRING *why = vstring_alloc(10);
 
108
    int     ret = 0;
 
109
 
 
110
    /*
 
111
     * Skip authentication when no authentication info exists for this
 
112
     * server, so that we talk to each other like strangers. Otherwise, if
 
113
     * authentication information exists, assume that authentication is
 
114
     * required, and assume that an authentication error is recoverable.
 
115
     */
 
116
    if (lmtp_sasl_passwd_lookup(state) != 0) {
 
117
        lmtp_sasl_start(state, VAR_LMTP_SASL_OPTS, var_lmtp_sasl_opts);
 
118
        if (lmtp_sasl_authenticate(state, why) <= 0)
 
119
            ret = lmtp_site_fail(state, 450, "Authentication failed: %s",
 
120
                                 vstring_str(why));
 
121
    }
 
122
    vstring_free(why);
 
123
    return (ret);
 
124
}
 
125
 
 
126
#endif