~ubuntu-branches/ubuntu/wily/dovecot/wily

« back to all changes in this revision

Viewing changes to src/lib-sasl/mech-login.c

  • Committer: Package Import Robot
  • Author(s): Jaldhar H. Vyas
  • Date: 2013-09-09 00:57:32 UTC
  • mfrom: (1.13.11)
  • mto: (4.8.5 experimental) (1.16.1)
  • mto: This revision was merged to the branch mainline in revision 97.
  • Revision ID: package-import@ubuntu.com-20130909005732-dn1eell8srqbhh0e
Tags: upstream-2.2.5
ImportĀ upstreamĀ versionĀ 2.2.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (c) 2013 Dovecot authors, see the included COPYING file */
 
2
 
 
3
#include "lib.h"
 
4
#include "str.h"
 
5
#include "dsasl-client-private.h"
 
6
 
 
7
enum login_state {
 
8
        STATE_INIT = 0,
 
9
        STATE_USER,
 
10
        STATE_PASS
 
11
};
 
12
 
 
13
struct login_dsasl_client {
 
14
        struct dsasl_client client;
 
15
        enum login_state state;
 
16
};
 
17
 
 
18
static int
 
19
mech_login_input(struct dsasl_client *_client,
 
20
                 const unsigned char *input ATTR_UNUSED,
 
21
                 unsigned int input_len ATTR_UNUSED,
 
22
                 const char **error_r)
 
23
{
 
24
        struct login_dsasl_client *client =
 
25
                (struct login_dsasl_client *)_client;
 
26
 
 
27
        if (client->state == STATE_PASS) {
 
28
                *error_r = "Server didn't finish authentication";
 
29
                return -1;
 
30
        }
 
31
        client->state++;
 
32
        return 0;
 
33
}
 
34
 
 
35
static int
 
36
mech_login_output(struct dsasl_client *_client,
 
37
                  const unsigned char **output_r, unsigned int *output_len_r,
 
38
                  const char **error_r)
 
39
{
 
40
        struct login_dsasl_client *client =
 
41
                (struct login_dsasl_client *)_client;
 
42
 
 
43
        if (_client->set.authid == NULL) {
 
44
                *error_r = "authid not set";
 
45
                return -1;
 
46
        }
 
47
        if (_client->password == NULL) {
 
48
                *error_r = "password not set";
 
49
                return -1;
 
50
        }
 
51
 
 
52
        switch (client->state) {
 
53
        case STATE_INIT:
 
54
                *output_r = &uchar_nul;
 
55
                *output_len_r = 0;
 
56
                return 0;
 
57
        case STATE_USER:
 
58
                *output_r = (const unsigned char *)_client->set.authid;
 
59
                *output_len_r = strlen(_client->set.authid);
 
60
                return 0;
 
61
        case STATE_PASS:
 
62
                *output_r = (const unsigned char *)_client->set.password;
 
63
                *output_len_r = strlen(_client->set.password);
 
64
                return 0;
 
65
        }
 
66
        i_unreached();
 
67
}
 
68
 
 
69
const struct dsasl_client_mech dsasl_client_mech_login = {
 
70
        .name = "LOGIN",
 
71
        .struct_size = sizeof(struct login_dsasl_client),
 
72
 
 
73
        .input = mech_login_input,
 
74
        .output = mech_login_output
 
75
};