~ubuntu-branches/ubuntu/edgy/dovecot/edgy-security

« back to all changes in this revision

Viewing changes to src/lib-auth/auth-server-request.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2006-06-30 15:13:37 UTC
  • mfrom: (1.10.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060630151337-l772crcoe5hfd4hw
Tags: 1.0.rc1-1ubuntu1
Merge from debian unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
        unsigned int retrying:1;
32
32
};
33
33
 
34
 
static bool auth_server_send_new_request(struct auth_server_connection *conn,
35
 
                                         struct auth_request *request);
 
34
static int auth_server_send_new_request(struct auth_server_connection *conn,
 
35
                                        struct auth_request *request,
 
36
                                        const char **error_r);
36
37
static void auth_client_request_free(struct auth_request *request);
37
38
 
38
39
static struct auth_server_connection *
50
51
static void
51
52
auth_server_request_check_retry(struct auth_request *request, const char *data)
52
53
{
 
54
        const char *error;
 
55
 
53
56
        if (strcmp(request->mech, "PLAIN") == 0 && data != NULL &&
54
57
            request->plaintext_data == NULL && request->conn != NULL) {
55
58
                request->next_conn = get_next_plain_server(request->conn);
60
63
 
61
64
                        hash_insert(request->next_conn->requests,
62
65
                                    POINTER_CAST(request->id), request);
63
 
                        auth_server_send_new_request(request->next_conn,
64
 
                                                     request);
65
 
                        request->retrying = TRUE;
 
66
                        if (auth_server_send_new_request(request->next_conn,
 
67
                                                         request, &error) == 0)
 
68
                                request->retrying = TRUE;
66
69
                }
67
70
        }
68
71
}
80
83
        return TRUE;
81
84
}
82
85
 
83
 
static bool auth_server_send_new_request(struct auth_server_connection *conn,
84
 
                                         struct auth_request *request)
 
86
static int auth_server_send_new_request(struct auth_server_connection *conn,
 
87
                                        struct auth_request *request,
 
88
                                        const char **error_r)
85
89
{
86
90
        string_t *str;
87
91
        ssize_t ret;
99
103
        if (request->cert_username != NULL) {
100
104
                if (!is_valid_string(request->cert_username)) {
101
105
                        t_pop();
102
 
                        return FALSE;
 
106
                        *error_r = "Invalid username in SSL certificate";
 
107
                        return -1;
103
108
                }
104
109
                str_printfa(str, "\tcert_username=%s", request->cert_username);
105
110
        }
107
112
                str_printfa(str, "\tlip=%s", net_ip2addr(&request->local_ip));
108
113
        if (request->remote_ip.family != 0)
109
114
                str_printfa(str, "\trip=%s", net_ip2addr(&request->remote_ip));
110
 
        if (request->initial_resp_base64 != NULL)
 
115
        if (request->initial_resp_base64 != NULL) {
 
116
                if (!is_valid_string(request->initial_resp_base64)) {
 
117
                        t_pop();
 
118
                        *error_r = "Invalid base64 data in initial response";
 
119
                        return -1;
 
120
                }
111
121
                str_printfa(str, "\tresp=%s", request->initial_resp_base64);
 
122
        }
112
123
        str_append_c(str, '\n');
113
124
 
114
125
        ret = o_stream_send(conn->output, str_data(str), str_len(str));
118
129
                errno = conn->output->stream_errno;
119
130
                i_warning("Error sending request to auth server: %m");
120
131
                auth_server_connection_destroy(&conn, TRUE);
121
 
                return FALSE;
 
132
                return -1;
122
133
        }
123
134
 
124
135
        auth_server_request_check_retry(request, request->initial_resp_base64);
125
 
        return TRUE;
 
136
        return 0;
126
137
}
127
138
 
128
139
static void auth_server_send_continue(struct auth_server_connection *conn,
222
233
{
223
234
        struct auth_request *request;
224
235
        struct auth_server_connection *next;
225
 
        const char *const *list;
 
236
        const char *const *list, *error;
226
237
        unsigned int id;
227
238
 
228
239
        list = t_strsplit(args, "\t");
259
270
                                    request);
260
271
                        request->next_conn = next;
261
272
 
262
 
                        auth_server_send_new_request(next, request);
 
273
                        (void)auth_server_send_new_request(next, request,
 
274
                                                           &error);
263
275
                        return TRUE;
264
276
                }
265
277
        }
349
361
 
350
362
        hash_insert(conn->requests, POINTER_CAST(request->id), request);
351
363
 
352
 
        if (!auth_server_send_new_request(conn, request))
 
364
        if (auth_server_send_new_request(conn, request, error_r) < 0)
353
365
                request = NULL;
354
366
        return request;
355
367
}