loudmouth/lm-sasl.c
author Mikael Berthe <mikael@lilotux.net>
Thu, 05 Nov 2015 21:47:40 +0100
changeset 672 71f60c55efb3
parent 664 f57b1b61e1fe
child 678 66017d9f6187
permissions -rw-r--r--
Update release information files Change the maintainers.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
516
4dd3aa6b83e5 Change the tab width to 4 steps in the emacs headers
Mikael Hallendal <micke@imendio.com>
parents: 515
diff changeset
     1
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     2
/*
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     3
 * Copyright (C) 2007 Collabora Ltd.
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     4
 *
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     6
 * modify it under the terms of the GNU Lesser General Public License as
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     7
 * published by the Free Software Foundation; either version 2 of the
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     8
 * License, or (at your option) any later version.
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
     9
 *
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    10
 * This program is distributed in the hope that it will be useful,
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    13
 * Lesser General Public License for more details.
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    14
 *
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    15
 * You should have received a copy of the GNU Lesser General Public
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    16
 * License along with this program; if not, write to the
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    17
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    18
 * Boston, MA 02111-1307, USA.
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    19
 */
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    20
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
    21
#include <config.h>
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
    22
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    23
#include <stdio.h>
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    24
#include <string.h>
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    25
#include <glib.h>
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    26
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
    27
#ifdef HAVE_GSSAPI
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
    28
#include <gssapi.h>
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
    29
#endif
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
    30
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    31
#include "lm-sock.h"
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    32
#include "lm-debug.h"
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    33
#include "lm-error.h"
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    34
#include "lm-internals.h"
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    35
#include "lm-message-queue.h"
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    36
#include "lm-misc.h"
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    37
#include "lm-ssl-internals.h"
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    38
#include "lm-parser.h"
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    39
#include "lm-sha.h"
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    40
#include "lm-connection.h"
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    41
#include "lm-utils.h"
431
04577a6b7ff7 Renamed LmSocket to LmOldSocket to make room for a new socket abstraction layer.
Mikael Hallendal <micke@imendio.com>
parents: 407
diff changeset
    42
#include "lm-old-socket.h"
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    43
#include "lm-sasl.h"
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    44
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    45
#include "md5.h"
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    46
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    47
typedef enum {
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    48
    AUTH_TYPE_PLAIN  = 1,
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
    49
    AUTH_TYPE_DIGEST = 2,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
    50
    AUTH_TYPE_GSSAPI = 4,
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    51
} AuthType;
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    52
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    53
typedef enum {
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    54
    SASL_AUTH_STATE_NO_MECH,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    55
    SASL_AUTH_STATE_PLAIN_STARTED,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    56
    SASL_AUTH_STATE_DIGEST_MD5_STARTED,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    57
    SASL_AUTH_STATE_DIGEST_MD5_SENT_AUTH_RESPONSE,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    58
    SASL_AUTH_STATE_DIGEST_MD5_SENT_FINAL_RESPONSE,
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
    59
    SASL_AUTH_STATE_GSSAPI_STARTED,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
    60
    SASL_AUTH_STATE_GSSAPI_SENT_AUTH_RESPONSE,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
    61
    SASL_AUTH_STATE_GSSAPI_SENT_FINAL_RESPONSE,
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    62
} SaslAuthState;
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    63
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    64
struct _LmSASL {
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    65
    LmConnection        *connection;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    66
    AuthType             auth_type;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    67
    SaslAuthState        state;
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
    68
    LmAuthParameters    *auth_params;
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    69
    gchar               *server;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    70
    gchar               *digest_md5_rspauth;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    71
    LmMessageHandler    *features_cb;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    72
    LmMessageHandler    *challenge_cb;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    73
    LmMessageHandler    *success_cb;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    74
    LmMessageHandler    *failure_cb;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    75
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    76
    gboolean             features_received;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    77
    gboolean             start_auth;
255
704881ac7788 Fixed potential problem if auth was not called from the open callback.
Mikael Hallendal <micke@imendio.com>
parents: 227
diff changeset
    78
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    79
    LmSASLResultHandler  handler;
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
    80
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
    81
#ifdef HAVE_GSSAPI
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
    82
    gss_ctx_id_t         gss_ctx;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
    83
    gss_name_t           gss_service;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
    84
#endif
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    85
};
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    86
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    87
#define XMPP_NS_SASL_AUTH "urn:ietf:params:xml:ns:xmpp-sasl"
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    88
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
    89
static LmHandlerResult     sasl_features_cb  (LmMessageHandler *handler,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    90
                                              LmConnection     *connection,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    91
                                              LmMessage        *message,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    92
                                              gpointer          user_data);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    93
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
    94
static LmHandlerResult     sasl_challenge_cb (LmMessageHandler *handler,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    95
                                              LmConnection     *connection,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    96
                                              LmMessage        *message,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
    97
                                              gpointer          user_data);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
    98
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
    99
static LmHandlerResult     sasl_success_cb   (LmMessageHandler *handler,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   100
                                              LmConnection     *connection,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   101
                                              LmMessage        *message,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   102
                                              gpointer          user_data);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   103
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   104
static LmHandlerResult     sasl_failure_cb   (LmMessageHandler *handler,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   105
                                              LmConnection     *connection,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   106
                                              LmMessage        *message,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   107
                                              gpointer          user_data);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   108
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   109
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   110
#ifdef HAVE_GSSAPI
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   111
static gboolean
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   112
sasl_gssapi_handle_challenge (LmSASL *sasl, LmMessageNode *node);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   113
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   114
static void
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 571
diff changeset
   115
sasl_gssapi_fail (LmSASL     *sasl,
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   116
                  const char *message,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   117
                  guint32     major_status,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   118
                  guint32     minor_status)
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   119
{
564
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   120
    guint32         err_major_status;
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   121
    guint32         err_minor_status;
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   122
    guint32         msg_ctx = 0;
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   123
    gss_buffer_desc major_status_string = GSS_C_EMPTY_BUFFER;
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   124
    gss_buffer_desc minor_status_string = GSS_C_EMPTY_BUFFER;
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   125
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   126
    err_major_status = gss_display_status (&err_minor_status, major_status,
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 571
diff changeset
   127
                                           GSS_C_GSS_CODE, GSS_C_NO_OID,
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   128
                                           &msg_ctx, &major_status_string);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   129
564
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   130
    if (!GSS_ERROR(err_major_status)) {
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   131
        err_major_status = gss_display_status (&err_minor_status, minor_status,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   132
                                               GSS_C_MECH_CODE, GSS_C_NULL_OID,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   133
                                               &msg_ctx, &minor_status_string);
564
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   134
    }
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   135
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   136
    g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SASL, "GSSAPI: %s: %s, %s", message,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   137
           (char *)major_status_string.value,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   138
           (char *)minor_status_string.value);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   139
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   140
    if (sasl->handler) {
564
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   141
        sasl->handler (sasl, sasl->connection, FALSE, "GSSAPI failure");
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   142
    }
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   143
564
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   144
    gss_release_buffer (&err_minor_status, &major_status_string);
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   145
    gss_release_buffer (&err_minor_status, &minor_status_string);
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   146
}
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   147
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   148
static gss_name_t
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   149
sasl_gssapi_get_creds (LmSASL *sasl)
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   150
{
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   151
    gss_buffer_desc token = GSS_C_EMPTY_BUFFER;
564
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   152
    gss_name_t      service_name = GSS_C_NO_NAME;
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   153
    guint32         major_status;
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   154
    guint32         minor_status;
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   155
664
f57b1b61e1fe Remove trailing whitespace and mixed indenting
Till Maas <opensource@till.name>
parents: 624
diff changeset
   156
    token.value        = g_strdup_printf ("xmpp@%s", sasl->server);
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   157
    token.length = strlen ((char *)token.value);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   158
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   159
    if (token.value == NULL) {
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   160
        return GSS_C_NO_NAME;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   161
    }
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   162
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   163
    major_status = gss_import_name (&minor_status, &token,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   164
                                    GSS_C_NT_HOSTBASED_SERVICE,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   165
                                    &service_name);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   166
564
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   167
    if (GSS_ERROR(major_status)) {
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   168
        sasl_gssapi_fail (sasl, "while obtaining service principal",
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   169
                          major_status, minor_status);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   170
        return GSS_C_NO_NAME;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   171
    }
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   172
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   173
    return service_name;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   174
}
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   175
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   176
static gboolean
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   177
sasl_gssapi_start (LmSASL *sasl, LmMessageNode *node)
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   178
{
564
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   179
    gchar           *response64;
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   180
    gss_buffer_desc  input_buffer_desc;
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   181
    gss_buffer_t     input_buffer;
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   182
    gss_buffer_desc  output_buffer_desc;
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   183
    gss_buffer_t     output_buffer;
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   184
    guint32          major_status;
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   185
    guint32          minor_status;
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   186
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   187
    sasl->gss_ctx = GSS_C_NO_CONTEXT;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   188
    sasl->gss_service = sasl_gssapi_get_creds (sasl);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   189
    if (sasl->gss_service == GSS_C_NO_NAME) {
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   190
        return FALSE;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   191
    }
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   192
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   193
    sasl->state = SASL_AUTH_STATE_GSSAPI_STARTED;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   194
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   195
    input_buffer_desc.value = NULL;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   196
    input_buffer_desc.length = 0;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   197
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   198
    input_buffer = &input_buffer_desc;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   199
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   200
    output_buffer_desc.value = NULL;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   201
    output_buffer_desc.length = 0;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   202
    output_buffer = &output_buffer_desc;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   203
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   204
    major_status = gss_init_sec_context (&minor_status,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   205
                                         GSS_C_NO_CREDENTIAL,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   206
                                         &sasl->gss_ctx,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   207
                                         sasl->gss_service,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   208
                                         GSS_C_NO_OID,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   209
                                         GSS_C_MUTUAL_FLAG |
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   210
                                         GSS_C_REPLAY_FLAG |
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   211
                                         GSS_C_SEQUENCE_FLAG |
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   212
                                         GSS_C_INTEG_FLAG |
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   213
                                         GSS_C_CONF_FLAG,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   214
                                         0,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   215
                                         GSS_C_NO_CHANNEL_BINDINGS,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   216
                                         input_buffer, NULL, output_buffer, NULL, NULL);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   217
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   218
    if (GSS_ERROR(major_status)) {
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   219
        sasl_gssapi_fail (sasl, "during challenge/response",
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   220
                          major_status, minor_status);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   221
        return FALSE;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   222
    }
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   223
564
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   224
    if (major_status != GSS_S_CONTINUE_NEEDED) {
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   225
        sasl->state = SASL_AUTH_STATE_GSSAPI_SENT_AUTH_RESPONSE;
564
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   226
    }
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   227
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   228
    response64 = g_base64_encode ((const guchar *) output_buffer_desc.value,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   229
                                  (gsize) output_buffer_desc.length);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   230
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   231
    lm_message_node_set_value (node, response64);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   232
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   233
    g_free (response64);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   234
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   235
    return TRUE;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   236
}
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   237
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   238
static gboolean
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   239
sasl_gssapi_handle_challenge (LmSASL *sasl, LmMessageNode *node)
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   240
{
564
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   241
    const gchar     *encoded;
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   242
    gchar           *response64;
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   243
    gss_buffer_t     input_buffer;
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   244
    gss_buffer_desc  input_buffer_desc;
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   245
    gss_buffer_t     output_buffer;
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   246
    gss_buffer_desc  output_buffer_desc;
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   247
    guint32          major_status;
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   248
    guint32          minor_status;
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   249
    gboolean         result;
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   250
    LmMessage       *msg;
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   251
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   252
    encoded = lm_message_node_get_value (node);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   253
    if (encoded == NULL) {
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   254
        input_buffer_desc.value = NULL;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   255
        input_buffer_desc.length = 0;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   256
    } else {
571
6fb1c4046db7 Fixed compile when GSSAPI support is enabled. [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 564
diff changeset
   257
        input_buffer_desc.value = g_base64_decode (encoded,
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   258
                                                 &input_buffer_desc.length);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   259
    }
564
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   260
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   261
    input_buffer = &input_buffer_desc;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   262
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   263
    output_buffer_desc.value = NULL;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   264
    output_buffer_desc.length = 0;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   265
    output_buffer = &output_buffer_desc;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   266
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   267
    if (sasl->state == SASL_AUTH_STATE_GSSAPI_STARTED) {
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   268
        major_status = gss_init_sec_context (&minor_status,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   269
                                             GSS_C_NO_CREDENTIAL,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   270
                                             &sasl->gss_ctx,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   271
                                             sasl->gss_service,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   272
                                             GSS_C_NO_OID,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   273
                                             GSS_C_MUTUAL_FLAG |
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   274
                                             GSS_C_REPLAY_FLAG |
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   275
                                             GSS_C_SEQUENCE_FLAG |
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   276
                                             GSS_C_INTEG_FLAG |
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   277
                                             GSS_C_CONF_FLAG,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   278
                                             0,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   279
                                             GSS_C_NO_CHANNEL_BINDINGS,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   280
                                             input_buffer, NULL, output_buffer, NULL, NULL);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   281
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   282
        if (GSS_ERROR(major_status)) {
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   283
            sasl_gssapi_fail (sasl, "during challenge/response",
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   284
                              major_status, minor_status);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   285
            return FALSE;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   286
        }
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   287
564
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   288
        if (major_status != GSS_S_CONTINUE_NEEDED) {
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   289
            sasl->state = SASL_AUTH_STATE_GSSAPI_SENT_AUTH_RESPONSE;
564
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   290
        }
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   291
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   292
        major_status = gss_release_buffer (&minor_status, input_buffer);
564
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   293
        if (major_status != GSS_S_COMPLETE) {
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   294
            return FALSE;
564
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   295
        }
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   296
    } else if (sasl->state == SASL_AUTH_STATE_GSSAPI_SENT_AUTH_RESPONSE) {
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   297
        gchar *features;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   298
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   299
        major_status = gss_unwrap (&minor_status, sasl->gss_ctx,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   300
                                   input_buffer, output_buffer,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   301
                                   NULL, NULL);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   302
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   303
        if (GSS_ERROR(major_status)) {
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   304
            sasl_gssapi_fail (sasl, "while unwrapping server capabilities",
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   305
                              major_status, minor_status);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   306
            return FALSE;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   307
        }
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   308
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   309
        major_status = gss_release_buffer (&minor_status, input_buffer);
564
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   310
        if (major_status != GSS_S_COMPLETE) {
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   311
            return FALSE;
564
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   312
        }
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   313
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   314
        major_status = gss_release_buffer (&minor_status, output_buffer);
564
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   315
        if (major_status != GSS_S_COMPLETE) {
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   316
            return FALSE;
564
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   317
        }
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   318
571
6fb1c4046db7 Fixed compile when GSSAPI support is enabled. [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 564
diff changeset
   319
        input_buffer_desc.length = 4 + strlen(lm_auth_parameters_get_username (sasl->auth_params));
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   320
        features = g_malloc (input_buffer_desc.length);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   321
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   322
        features[0] = 1;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   323
        features[1] = 0xFF;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   324
        features[2] = 0xFF;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   325
        features[3] = 0xFF;
571
6fb1c4046db7 Fixed compile when GSSAPI support is enabled. [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 564
diff changeset
   326
        strcpy(features+4, lm_auth_parameters_get_username (sasl->auth_params));
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   327
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   328
        input_buffer_desc.value = features;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   329
        major_status = gss_wrap (&minor_status, sasl->gss_ctx,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   330
                                 0, /* Just integrity checking here */
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   331
                                 GSS_C_QOP_DEFAULT,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   332
                                 input_buffer,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   333
                                 NULL,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   334
                                 output_buffer);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   335
        g_free (features);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   336
        if (GSS_ERROR(major_status)) {
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   337
            sasl_gssapi_fail (sasl, "while wrapping required features",
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   338
                              major_status, minor_status);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   339
            return FALSE;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   340
        }
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   341
    } else {
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   342
        g_assert_not_reached ();
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   343
    }
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   344
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   345
    msg = lm_message_new (NULL, LM_MESSAGE_TYPE_RESPONSE);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   346
    lm_message_node_set_attributes (msg->node,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   347
                                    "xmlns", XMPP_NS_SASL_AUTH,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   348
                                    NULL);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   349
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   350
    if (output_buffer_desc.value != NULL) {
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 571
diff changeset
   351
        response64 = g_base64_encode ((const guchar *) output_buffer_desc.value,
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   352
                                      (gsize) output_buffer_desc.length);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   353
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   354
    } else {
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   355
        response64 = g_strdup ("");
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   356
    }
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   357
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   358
    major_status = gss_release_buffer (&minor_status, output_buffer);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   359
    if (major_status != GSS_S_COMPLETE) {
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   360
        g_free (response64);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   361
        lm_message_unref (msg);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   362
        return FALSE;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   363
    }
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   364
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   365
    lm_message_node_set_value (msg->node, response64);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   366
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   367
    result = lm_connection_send (sasl->connection, msg, NULL);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   368
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   369
    g_free (response64);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   370
    lm_message_unref (msg);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   371
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   372
    if (!result) {
614
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
   373
        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET,
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
   374
               "Failed to send SASL response\n");
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   375
        return FALSE;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   376
    }
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   377
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   378
    return TRUE;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   379
}
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   380
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   381
static gboolean
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   382
sasl_gssapi_finish (LmSASL *sasl, LmMessageNode *node)
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   383
{
624
a94013a4555d Fix some gcc warnings
Mikael Berthe <mikael@lilotux.net>
parents: 614
diff changeset
   384
    OM_uint32 /* major_status, */ minor_status;
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   385
564
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   386
    if (sasl->gss_service != GSS_C_NO_NAME) {
624
a94013a4555d Fix some gcc warnings
Mikael Berthe <mikael@lilotux.net>
parents: 614
diff changeset
   387
        /* major_status = */
a94013a4555d Fix some gcc warnings
Mikael Berthe <mikael@lilotux.net>
parents: 614
diff changeset
   388
        (void) gss_release_name (&minor_status, &sasl->gss_service);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 571
diff changeset
   389
    }
564
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   390
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   391
    if (sasl->gss_ctx != GSS_C_NO_CONTEXT) {
624
a94013a4555d Fix some gcc warnings
Mikael Berthe <mikael@lilotux.net>
parents: 614
diff changeset
   392
        /* major_status = */
a94013a4555d Fix some gcc warnings
Mikael Berthe <mikael@lilotux.net>
parents: 614
diff changeset
   393
        (void) gss_delete_sec_context (&minor_status, &sasl->gss_ctx,
a94013a4555d Fix some gcc warnings
Mikael Berthe <mikael@lilotux.net>
parents: 614
diff changeset
   394
                                       GSS_C_NO_BUFFER);
564
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   395
    }
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   396
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   397
    return TRUE;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   398
}
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   399
#endif
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   400
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   401
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   402
/* DIGEST-MD5 mechanism code from libgibber */
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   403
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   404
static gchar *
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 571
diff changeset
   405
sasl_strndup_unescaped (const gchar *str, gsize len)
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   406
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   407
    const gchar *s;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   408
    gchar       *d;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   409
    gchar       *ret;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   410
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   411
    ret = g_malloc0 (len + 1);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   412
    for (s = str, d = ret ; s < (str + len) ; s++, d++) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   413
        if (*s == '\\') s++;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   414
        *d = *s;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   415
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   416
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   417
    return ret;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   418
}
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   419
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   420
static GHashTable *
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   421
sasl_digest_md5_challenge_to_hash (const gchar * challenge)
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   422
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   423
    const gchar *keystart, *keyend, *valstart;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   424
    const gchar *c = challenge;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   425
    gchar       *key, *val;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   426
    GHashTable  *result;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 571
diff changeset
   427
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 571
diff changeset
   428
    result = g_hash_table_new_full (g_str_hash, g_str_equal,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   429
                                    g_free, g_free);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   430
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 571
diff changeset
   431
    do {
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   432
        while (g_ascii_isspace(*c)) c++;
270
7247db75f528 Skip whitespace before SASL MD5 digest. Patch by Senko Rašić.
Dafydd Harries <daf@rhydd.org>
parents: 255
diff changeset
   433
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   434
        keystart = c;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   435
        for (; *c != '\0' && *c != '='; c++);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   436
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   437
        if (*c == '\0' || c == keystart) goto error;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   438
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 571
diff changeset
   439
        keyend = c;
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   440
        c++;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   441
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   442
        if (*c == '"') {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   443
            c++;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   444
            valstart = c;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   445
            for (; *c != '\0' && *c != '"'; c++);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   446
            if (*c == '\0' || c == valstart) goto error;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   447
            val = sasl_strndup_unescaped (valstart, c - valstart);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   448
            c++;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   449
        } else {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   450
            valstart = c;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   451
            for (; *c !=  '\0' && *c != ','; c++);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   452
            if (c == valstart) goto error;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   453
            val = g_strndup (valstart, c - valstart);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   454
        }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   455
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   456
        key = g_strndup (keystart, keyend - keystart);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   457
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   458
        g_hash_table_insert (result, key, val);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   459
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   460
        if (*c == ',') c++;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   461
    } while (*c != '\0');
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   462
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   463
    return result;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   464
 error:
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 571
diff changeset
   465
    g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SASL,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   466
           "Failed to parse challenge: %s", challenge);
255
704881ac7788 Fixed potential problem if auth was not called from the open callback.
Mikael Hallendal <micke@imendio.com>
parents: 227
diff changeset
   467
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   468
    g_hash_table_destroy (result);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   469
    return NULL;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   470
}
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   471
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   472
static gchar *
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 571
diff changeset
   473
sasl_md5_hex_hash (gchar *value, gsize len)
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   474
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   475
    md5_byte_t   digest_md5[16];
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   476
    md5_state_t  md5_calc;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   477
    GString     *str;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   478
    int          i;
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   479
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   480
    str = g_string_sized_new (32);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   481
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   482
    md5_init (&md5_calc);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   483
    md5_append (&md5_calc, (const md5_byte_t *)value, len);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   484
    md5_finish (&md5_calc, digest_md5);
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   485
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   486
    for (i = 0 ; i < 16 ; i++) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   487
        g_string_append_printf (str, "%02x", digest_md5[i]);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   488
    }
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   489
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   490
    return g_string_free (str, FALSE);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   491
}
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   492
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   493
static gchar *
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   494
sasl_digest_md5_generate_cnonce(void)
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   495
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   496
    /* RFC 2831 recommends the the nonce to be either hexadecimal or base64 with
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   497
     * at least 64 bits of entropy */
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   498
#define NR 8
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 571
diff changeset
   499
    guint32 n[NR];
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   500
    int i;
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   501
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   502
    for (i = 0; i < NR; i++) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   503
        n[i] = g_random_int();
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   504
    }
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   505
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   506
    return g_base64_encode ((const guchar *)n, (gsize)sizeof(n));
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   507
}
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   508
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   509
static gchar *
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   510
sasl_md5_prepare_response (LmSASL *sasl, GHashTable *challenge)
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   511
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   512
    GString     *response;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   513
    const gchar *realm, *nonce;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   514
    gchar       *a1, *a1h, *a2, *a2h, *kd, *kdh;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   515
    gchar       *cnonce = NULL;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   516
    gchar       *tmp;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   517
    md5_byte_t   digest_md5[16];
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   518
    md5_state_t  md5_calc;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   519
    gsize        len;
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   520
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   521
    response = g_string_new ("");
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   522
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   523
    if (sasl->auth_params == NULL) {
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   524
        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SASL,
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   525
               "%s: no authentication parameters provided", G_STRFUNC);
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   526
        if (sasl->handler) {
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 571
diff changeset
   527
            sasl->handler (sasl, sasl->connection,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   528
                           FALSE, "no username/password provided");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   529
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   530
        goto error;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   531
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   532
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   533
    nonce = g_hash_table_lookup (challenge, "nonce");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   534
    if (nonce == NULL || nonce == '\0') {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   535
        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SASL,
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 571
diff changeset
   536
               "%s: server didn't provide a nonce in the challenge",
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   537
               G_STRFUNC);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   538
        if (sasl->handler) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   539
            sasl->handler (sasl, sasl->connection,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   540
                           FALSE, "server error");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   541
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   542
        goto error;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   543
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   544
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   545
    cnonce = sasl_digest_md5_generate_cnonce ();
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   546
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   547
    /* FIXME challenge can contain multiple realms */
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   548
    realm = g_hash_table_lookup (challenge, "realm");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   549
    if (realm == NULL) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   550
        realm = sasl->server;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   551
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   552
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   553
    /* FIXME properly escape values */
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   554
    g_string_append_printf (response, "username=\"%s\"", lm_auth_parameters_get_username (sasl->auth_params));
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   555
    g_string_append_printf (response, ",realm=\"%s\"", realm);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   556
    g_string_append_printf (response, ",digest-uri=\"xmpp/%s\"", realm);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   557
    g_string_append_printf (response, ",nonce=\"%s\",nc=00000001", nonce);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   558
    g_string_append_printf (response, ",cnonce=\"%s\"", cnonce);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   559
    /* FIXME should check if auth is in the cop challenge val */
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   560
    g_string_append_printf (response, ",qop=auth,charset=utf-8");
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   561
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 571
diff changeset
   562
    tmp = g_strdup_printf ("%s:%s:%s",
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 571
diff changeset
   563
                           lm_auth_parameters_get_username (sasl->auth_params),
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   564
                           realm, lm_auth_parameters_get_password (sasl->auth_params));
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 571
diff changeset
   565
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   566
    md5_init (&md5_calc);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   567
    md5_append (&md5_calc, (const md5_byte_t *)tmp, strlen(tmp));
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   568
    md5_finish (&md5_calc, digest_md5);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   569
    g_free (tmp);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   570
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   571
    a1 = g_strdup_printf ("0123456789012345:%s:%s", nonce, cnonce);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   572
    len = strlen (a1);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   573
    memcpy (a1, digest_md5, 16);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   574
    a1h = sasl_md5_hex_hash (a1, len);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   575
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   576
    a2 = g_strdup_printf ("AUTHENTICATE:xmpp/%s", realm);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   577
    a2h = sasl_md5_hex_hash (a2, strlen(a2));
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   578
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   579
    kd = g_strdup_printf ("%s:%s:00000001:%s:auth:%s",
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   580
                          a1h, nonce, cnonce, a2h);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   581
    kdh = sasl_md5_hex_hash (kd, strlen(kd));
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   582
    g_string_append_printf (response, ",response=%s", kdh);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   583
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   584
    g_free (kd);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   585
    g_free (kdh);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   586
    g_free (a2);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   587
    g_free (a2h);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   588
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   589
    /* Calculate the response we expect from the server */
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   590
    a2 = g_strdup_printf (":xmpp/%s", realm);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   591
    a2h = sasl_md5_hex_hash (a2, strlen(a2));
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   592
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   593
    kd = g_strdup_printf ("%s:%s:00000001:%s:auth:%s", a1h, nonce, cnonce, a2h);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   594
    g_free (sasl->digest_md5_rspauth);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   595
    sasl->digest_md5_rspauth = sasl_md5_hex_hash (kd, strlen(kd));
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   596
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   597
    g_free (a1);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   598
    g_free (a1h);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   599
    g_free (a2);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   600
    g_free (a2h);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   601
    g_free (kd);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   602
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   603
 out:
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   604
    g_free (cnonce);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   605
    if (response) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   606
        return g_string_free (response, FALSE);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   607
    } else {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   608
        return NULL;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   609
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   610
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   611
 error:
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   612
    g_string_free (response, TRUE);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   613
    response = NULL;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   614
    goto out;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   615
}
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   616
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   617
static gboolean
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   618
sasl_digest_md5_send_initial_response (LmSASL *sasl, GHashTable *challenge)
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   619
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   620
    LmMessage *msg;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   621
    gchar     *response;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   622
    gchar     *response64;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   623
    int        result;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   624
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   625
    response = sasl_md5_prepare_response (sasl, challenge);
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   626
    if (response == NULL) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   627
        return FALSE;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   628
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   629
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 571
diff changeset
   630
    response64 = g_base64_encode ((const guchar *) response,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   631
                                  (gsize) strlen(response));
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   632
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   633
    msg = lm_message_new (NULL, LM_MESSAGE_TYPE_RESPONSE);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   634
    lm_message_node_set_attributes (msg->node,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   635
                                    "xmlns", XMPP_NS_SASL_AUTH,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   636
                                    NULL);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   637
    lm_message_node_set_value (msg->node, response64);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   638
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   639
    result = lm_connection_send (sasl->connection, msg, NULL);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   640
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   641
    g_free (response);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   642
    g_free (response64);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   643
    lm_message_unref (msg);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   644
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   645
    if (!result) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   646
        return FALSE;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   647
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   648
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   649
    sasl->state = SASL_AUTH_STATE_DIGEST_MD5_SENT_AUTH_RESPONSE;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   650
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   651
    return TRUE;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   652
}
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   653
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   654
static gboolean
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   655
sasl_digest_md5_check_server_response(LmSASL *sasl, GHashTable *challenge)
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   656
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   657
    LmMessage   *msg;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   658
    const gchar *rspauth;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   659
    int          result;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   660
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   661
    rspauth = g_hash_table_lookup (challenge, "rspauth");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   662
    if (rspauth == NULL) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   663
        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SSL,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   664
               "%s: server sent an invalid reply (no rspauth)\n",
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   665
               G_STRFUNC);
224
447f16217278 Use g_log instead of g_debug
Mikael Hallendal <micke@imendio.com>
parents: 216
diff changeset
   666
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   667
        if (sasl->handler) {
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 571
diff changeset
   668
            sasl->handler (sasl, sasl->connection,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   669
                           TRUE, "server error");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   670
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   671
        return FALSE;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   672
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   673
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   674
    if (strcmp (sasl->digest_md5_rspauth, rspauth) != 0) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   675
        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SSL,
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 571
diff changeset
   676
               "%s: server sent an invalid reply (rspauth not matching)\n",
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   677
               G_STRFUNC);
224
447f16217278 Use g_log instead of g_debug
Mikael Hallendal <micke@imendio.com>
parents: 216
diff changeset
   678
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   679
        if (sasl->handler) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   680
            sasl->handler (sasl, sasl->connection,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   681
                           TRUE, "server error");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   682
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   683
        return FALSE;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   684
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   685
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   686
    msg = lm_message_new (NULL, LM_MESSAGE_TYPE_RESPONSE);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   687
    lm_message_node_set_attributes (msg->node,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   688
                                    "xmlns", XMPP_NS_SASL_AUTH,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   689
                                    NULL);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   690
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   691
    result = lm_connection_send (sasl->connection, msg, NULL);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   692
    lm_message_unref (msg);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   693
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   694
    if (!result) {
614
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
   695
        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET,
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
   696
               "Failed to send SASL response\n");
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   697
        return FALSE;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   698
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   699
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   700
    sasl->state = SASL_AUTH_STATE_DIGEST_MD5_SENT_FINAL_RESPONSE;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   701
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   702
    return TRUE;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   703
}
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   704
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   705
static gboolean
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   706
sasl_digest_md5_handle_challenge (LmSASL *sasl, LmMessageNode *node)
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   707
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   708
    const gchar *encoded;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   709
    gchar       *challenge;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   710
    gsize        len;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   711
    GHashTable  *h;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   712
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   713
    encoded = lm_message_node_get_value (node);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   714
    if (!encoded) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   715
        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SASL,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   716
               "%s: got empty challenge!", G_STRFUNC);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   717
        return FALSE;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   718
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   719
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   720
    challenge = (gchar *) g_base64_decode (encoded, &len);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   721
    h = sasl_digest_md5_challenge_to_hash (challenge);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   722
    g_free(challenge);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   723
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   724
    if (!h) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   725
        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SASL,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   726
               "%s: server sent an invalid challenge", G_STRFUNC);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   727
        if (sasl->handler) {
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 571
diff changeset
   728
            sasl->handler (sasl, sasl->connection,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   729
                           FALSE, "server error");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   730
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   731
        return FALSE;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   732
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   733
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   734
    switch (sasl->state) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   735
    case SASL_AUTH_STATE_DIGEST_MD5_STARTED:
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 571
diff changeset
   736
        sasl_digest_md5_send_initial_response (sasl, h);
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   737
        break;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   738
    case SASL_AUTH_STATE_DIGEST_MD5_SENT_AUTH_RESPONSE:
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 571
diff changeset
   739
        sasl_digest_md5_check_server_response (sasl, h);
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   740
        break;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   741
    default:
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   742
        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SASL,
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 571
diff changeset
   743
               "%s: server sent a challenge at the wrong time",
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   744
               G_STRFUNC);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   745
        if (sasl->handler) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   746
            sasl->handler (sasl, sasl->connection,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   747
                           FALSE, "server error");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   748
        }
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   749
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   750
        return FALSE;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 571
diff changeset
   751
    }
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   752
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   753
    g_hash_table_destroy(h);
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   754
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   755
    return TRUE;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   756
}
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   757
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   758
static LmHandlerResult
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   759
sasl_challenge_cb (LmMessageHandler *handler,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   760
                   LmConnection     *connection,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   761
                   LmMessage        *message,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   762
                   gpointer          user_data)
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   763
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   764
    LmSASL      *sasl;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   765
    const gchar *ns;
224
447f16217278 Use g_log instead of g_debug
Mikael Hallendal <micke@imendio.com>
parents: 216
diff changeset
   766
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   767
    ns = lm_message_node_get_attribute (message->node, "xmlns");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   768
    if (!ns || strcmp (ns, XMPP_NS_SASL_AUTH) != 0) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   769
        return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   770
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   771
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   772
    sasl = (LmSASL *) user_data;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   773
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   774
    switch (sasl->auth_type) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   775
    case AUTH_TYPE_PLAIN:
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   776
        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SSL,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   777
               "%s: server sent challenge for PLAIN mechanism",
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   778
               G_STRFUNC);
224
447f16217278 Use g_log instead of g_debug
Mikael Hallendal <micke@imendio.com>
parents: 216
diff changeset
   779
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   780
        if (sasl->handler) {
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 571
diff changeset
   781
            sasl->handler (sasl, sasl->connection,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   782
                           FALSE, "server error");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   783
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   784
        break;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   785
    case AUTH_TYPE_DIGEST:
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   786
        sasl_digest_md5_handle_challenge (sasl, message->node);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   787
        break;
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   788
#ifdef HAVE_GSSAPI
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   789
    case AUTH_TYPE_GSSAPI:
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   790
        sasl_gssapi_handle_challenge(sasl, message->node);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   791
        break;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   792
#endif
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   793
    default:
614
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
   794
        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET, "Wrong auth type");
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   795
        break;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   796
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   797
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   798
    return LM_HANDLER_RESULT_REMOVE_MESSAGE;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   799
}
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   800
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   801
static LmHandlerResult
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   802
sasl_success_cb (LmMessageHandler *handler,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   803
                 LmConnection     *connection,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   804
                 LmMessage        *message,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   805
                 gpointer          user_data)
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   806
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   807
    LmSASL      *sasl;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   808
    const gchar *ns;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 571
diff changeset
   809
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   810
    ns = lm_message_node_get_attribute (message->node, "xmlns");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   811
    if (!ns || strcmp (ns, XMPP_NS_SASL_AUTH) != 0) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   812
        return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   813
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   814
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   815
    sasl = (LmSASL *) user_data;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   816
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   817
    switch (sasl->auth_type) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   818
    case AUTH_TYPE_PLAIN:
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   819
        if (sasl->state != SASL_AUTH_STATE_PLAIN_STARTED) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   820
            g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SASL,
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 571
diff changeset
   821
                   "%s: server sent success before finishing auth",
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   822
                   G_STRFUNC);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   823
            if (sasl->handler) {
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 571
diff changeset
   824
                sasl->handler (sasl, sasl->connection,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   825
                               FALSE, "server error");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   826
            }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   827
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   828
        break;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   829
    case AUTH_TYPE_DIGEST:
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   830
        if (sasl->state != SASL_AUTH_STATE_DIGEST_MD5_SENT_AUTH_RESPONSE &&
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   831
            sasl->state != SASL_AUTH_STATE_DIGEST_MD5_SENT_FINAL_RESPONSE) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   832
            g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SASL,
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 571
diff changeset
   833
                   "%s: server sent success before finishing auth",
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   834
                   G_STRFUNC);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   835
            if (sasl->handler) {
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 571
diff changeset
   836
                sasl->handler (sasl, sasl->connection,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   837
                               FALSE, "server error");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   838
            }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   839
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   840
        break;
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   841
#ifdef HAVE_GSSAPI
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   842
    case AUTH_TYPE_GSSAPI:
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   843
        if (sasl->state != SASL_AUTH_STATE_GSSAPI_SENT_AUTH_RESPONSE &&
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   844
            sasl->state != SASL_AUTH_STATE_GSSAPI_SENT_FINAL_RESPONSE) {
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   845
            sasl_gssapi_finish(sasl, message->node);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 571
diff changeset
   846
            g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SASL,
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   847
                   "%s: server sent success before starting auth",
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   848
                   G_STRFUNC);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   849
            if (sasl->handler) {
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   850
                sasl->handler (sasl, sasl->connection,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   851
                               FALSE, "server error");
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   852
            }
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   853
        }
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   854
        break;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   855
#endif
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   856
    default:
614
773201ca404c Replaced every g_warning() with g_log()
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
   857
        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET, "Wrong auth type");
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   858
        break;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   859
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   860
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   861
    g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SASL,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   862
           "%s: SASL authentication successful", G_STRFUNC);
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   863
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   864
    if (sasl->handler) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   865
        sasl->handler (sasl, sasl->connection, TRUE, NULL);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   866
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   867
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   868
    return LM_HANDLER_RESULT_REMOVE_MESSAGE;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 571
diff changeset
   869
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   870
}
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   871
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   872
static LmHandlerResult
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   873
sasl_failure_cb (LmMessageHandler *handler,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   874
                 LmConnection     *connection,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   875
                 LmMessage        *message,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   876
                 gpointer          user_data)
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   877
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   878
    LmSASL      *sasl;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   879
    const gchar *ns;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   880
    const gchar *reason = "unknown reason";
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 571
diff changeset
   881
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   882
    ns = lm_message_node_get_attribute (message->node, "xmlns");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   883
    if (!ns || strcmp (ns, XMPP_NS_SASL_AUTH) != 0) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   884
        return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   885
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   886
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   887
    sasl = (LmSASL *) user_data;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   888
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   889
    if (message->node->children) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   890
        const gchar *r;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 571
diff changeset
   891
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   892
        r = lm_message_node_get_value (message->node->children);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   893
        if (r) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   894
            reason = r;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   895
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   896
    }
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 571
diff changeset
   897
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   898
    g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SASL,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   899
           "%s: SASL authentication failed: %s", G_STRFUNC, reason);
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   900
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   901
    if (sasl->handler) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   902
        sasl->handler (sasl, sasl->connection, FALSE, reason);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   903
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   904
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   905
    return LM_HANDLER_RESULT_REMOVE_MESSAGE;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   906
}
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   907
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   908
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   909
static gboolean
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   910
sasl_start (LmSASL *sasl)
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   911
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   912
    LmMessage  *auth_msg;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   913
    gboolean    result;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   914
    const char *mech = NULL;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   915
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   916
    auth_msg = lm_message_new (NULL, LM_MESSAGE_TYPE_AUTH);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   917
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   918
    if (sasl->auth_type == AUTH_TYPE_PLAIN) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   919
        GString *str;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   920
        gchar   *cstr;
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   921
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   922
        str = g_string_new ("");
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   923
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   924
        mech = "PLAIN";
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   925
        sasl->state = SASL_AUTH_STATE_PLAIN_STARTED;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   926
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   927
        if (sasl->auth_params == NULL) {
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   928
            g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SASL,
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 571
diff changeset
   929
                   "%s: no authentication parameters provided",
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   930
                   G_STRFUNC);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   931
            if (sasl->handler) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   932
                sasl->handler (sasl, sasl->connection, FALSE, "no username/password provided");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   933
            }
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   934
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   935
            return FALSE;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   936
        }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   937
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   938
        g_string_append_c (str, '\0');
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   939
        g_string_append (str, lm_auth_parameters_get_username (sasl->auth_params));
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   940
        g_string_append_c (str, '\0');
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   941
        g_string_append (str, lm_auth_parameters_get_password (sasl->auth_params));
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 571
diff changeset
   942
        cstr = g_base64_encode ((const guchar *) str->str,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   943
                                (gsize) str->len);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   944
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   945
        lm_message_node_set_value (auth_msg->node, cstr);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   946
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   947
        g_string_free (str, TRUE);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   948
        g_free (cstr);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   949
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   950
        /* Here we say the Google magic word. Bad Google. */
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   951
        lm_message_node_set_attributes (auth_msg->node,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   952
                                        "xmlns:ga", "http://www.google.com/talk/protocol/auth",
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   953
                                        "ga:client-uses-full-bind-result", "true",
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   954
                                        NULL);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   955
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 571
diff changeset
   956
    }
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   957
    else if (sasl->auth_type == AUTH_TYPE_DIGEST) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   958
        mech = "DIGEST-MD5";
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   959
        sasl->state = SASL_AUTH_STATE_DIGEST_MD5_STARTED;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   960
    }
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   961
#ifdef HAVE_GSSAPI
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   962
    else if (sasl->auth_type == AUTH_TYPE_GSSAPI) {
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   963
        mech = "GSSAPI";
564
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   964
        sasl_gssapi_start (sasl, auth_msg->node);
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   965
    }
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   966
#endif
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   967
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   968
    lm_message_node_set_attributes (auth_msg->node,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   969
                                    "xmlns", XMPP_NS_SASL_AUTH,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   970
                                    "mechanism", mech,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   971
                                    NULL);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   972
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   973
    result = lm_connection_send (sasl->connection, auth_msg, NULL);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   974
    lm_message_unref (auth_msg);
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   975
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   976
    if (!result) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   977
        return FALSE;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   978
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   979
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   980
    return TRUE;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   981
}
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   982
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   983
static gboolean
255
704881ac7788 Fixed potential problem if auth was not called from the open callback.
Mikael Hallendal <micke@imendio.com>
parents: 227
diff changeset
   984
sasl_set_auth_type (LmSASL *sasl, LmMessageNode *mechanisms)
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   985
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   986
    LmMessageNode *m;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   987
    const gchar   *ns;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   988
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   989
    sasl->auth_type = 0;
255
704881ac7788 Fixed potential problem if auth was not called from the open callback.
Mikael Hallendal <micke@imendio.com>
parents: 227
diff changeset
   990
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   991
    ns = lm_message_node_get_attribute (mechanisms, "xmlns");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   992
    if (!ns || strcmp (ns, XMPP_NS_SASL_AUTH) != 0) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   993
        return FALSE;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   994
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   995
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   996
    for (m = mechanisms->children; m; m = m->next) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   997
        const gchar *name;
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   998
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   999
        name = lm_message_node_get_value (m);
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
  1000
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1001
        if (!name) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1002
            continue;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1003
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1004
        if (strcmp (name, "PLAIN") == 0) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1005
            sasl->auth_type |= AUTH_TYPE_PLAIN;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1006
            continue;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1007
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1008
        if (strcmp (name, "DIGEST-MD5") == 0) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1009
            sasl->auth_type |= AUTH_TYPE_DIGEST;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1010
            continue;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1011
        }
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
  1012
        if (strcmp (name, "GSSAPI") == 0) {
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
  1013
            sasl->auth_type |= AUTH_TYPE_GSSAPI;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
  1014
            continue;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
  1015
        }
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 571
diff changeset
  1016
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1017
        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SASL,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1018
               "%s: unknown SASL auth mechanism: %s", G_STRFUNC, name);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1019
    }
255
704881ac7788 Fixed potential problem if auth was not called from the open callback.
Mikael Hallendal <micke@imendio.com>
parents: 227
diff changeset
  1020
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1021
    return TRUE;
255
704881ac7788 Fixed potential problem if auth was not called from the open callback.
Mikael Hallendal <micke@imendio.com>
parents: 227
diff changeset
  1022
}
704881ac7788 Fixed potential problem if auth was not called from the open callback.
Mikael Hallendal <micke@imendio.com>
parents: 227
diff changeset
  1023
704881ac7788 Fixed potential problem if auth was not called from the open callback.
Mikael Hallendal <micke@imendio.com>
parents: 227
diff changeset
  1024
static gboolean
704881ac7788 Fixed potential problem if auth was not called from the open callback.
Mikael Hallendal <micke@imendio.com>
parents: 227
diff changeset
  1025
sasl_authenticate (LmSASL *sasl)
704881ac7788 Fixed potential problem if auth was not called from the open callback.
Mikael Hallendal <micke@imendio.com>
parents: 227
diff changeset
  1026
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1027
    if (sasl->auth_type == 0) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1028
        g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SASL,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1029
               "%s: no supported SASL auth mechanisms found",
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1030
               G_STRFUNC);
255
704881ac7788 Fixed potential problem if auth was not called from the open callback.
Mikael Hallendal <micke@imendio.com>
parents: 227
diff changeset
  1031
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1032
        return FALSE;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1033
    }
255
704881ac7788 Fixed potential problem if auth was not called from the open callback.
Mikael Hallendal <micke@imendio.com>
parents: 227
diff changeset
  1034
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
  1035
    /* Prefer GSSAPI if available */
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
  1036
#ifdef HAVE_GSSAPI
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
  1037
    if (sasl->auth_type & AUTH_TYPE_GSSAPI) {
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
  1038
        sasl->auth_type = AUTH_TYPE_GSSAPI;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
  1039
        return sasl_start (sasl);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
  1040
    }
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
  1041
#endif
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
  1042
    /* Otherwise prefer DIGEST */
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
  1043
    else if (sasl->auth_type & AUTH_TYPE_DIGEST) {
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1044
        sasl->auth_type = AUTH_TYPE_DIGEST;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1045
        return sasl_start (sasl);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1046
    }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1047
    else if (sasl->auth_type & AUTH_TYPE_PLAIN) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1048
        sasl->auth_type = AUTH_TYPE_PLAIN;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1049
        return sasl_start (sasl);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 571
diff changeset
  1050
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1051
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1052
    return FALSE;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1053
}
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1054
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1055
static LmHandlerResult
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
  1056
sasl_features_cb (LmMessageHandler *handler,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1057
                  LmConnection     *connection,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1058
                  LmMessage        *message,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1059
                  gpointer          user_data)
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1060
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1061
    LmMessageNode *mechanisms;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1062
    LmSASL        *sasl;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1063
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1064
    g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SASL, "Stream features received\n");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1065
    mechanisms = lm_message_node_find_child (message->node, "mechanisms");
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1066
    if (!mechanisms) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1067
        return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1068
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1069
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1070
    sasl = (LmSASL *) user_data;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1071
    sasl->features_received = TRUE;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1072
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1073
    sasl_set_auth_type (sasl, mechanisms);
255
704881ac7788 Fixed potential problem if auth was not called from the open callback.
Mikael Hallendal <micke@imendio.com>
parents: 227
diff changeset
  1074
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1075
    if (sasl->start_auth) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1076
        sasl_authenticate (sasl);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1077
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1078
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1079
    return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1080
}
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1081
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
  1082
LmSASL *
255
704881ac7788 Fixed potential problem if auth was not called from the open callback.
Mikael Hallendal <micke@imendio.com>
parents: 227
diff changeset
  1083
lm_sasl_new (LmConnection *connection)
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
  1084
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1085
    LmSASL *sasl;
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 571
diff changeset
  1086
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1087
    sasl = g_new0 (LmSASL, 1);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1088
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1089
    sasl->connection = connection;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1090
    sasl->features_received = FALSE;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1091
    sasl->start_auth = FALSE;
255
704881ac7788 Fixed potential problem if auth was not called from the open callback.
Mikael Hallendal <micke@imendio.com>
parents: 227
diff changeset
  1092
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1093
    sasl->features_cb = lm_message_handler_new (sasl_features_cb,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1094
                                                sasl,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1095
                                                NULL);
255
704881ac7788 Fixed potential problem if auth was not called from the open callback.
Mikael Hallendal <micke@imendio.com>
parents: 227
diff changeset
  1096
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1097
    lm_connection_register_message_handler (connection,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1098
                                            sasl->features_cb,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1099
                                            LM_MESSAGE_TYPE_STREAM_FEATURES,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1100
                                            LM_HANDLER_PRIORITY_LAST);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1101
    return sasl;
255
704881ac7788 Fixed potential problem if auth was not called from the open callback.
Mikael Hallendal <micke@imendio.com>
parents: 227
diff changeset
  1102
}
704881ac7788 Fixed potential problem if auth was not called from the open callback.
Mikael Hallendal <micke@imendio.com>
parents: 227
diff changeset
  1103
704881ac7788 Fixed potential problem if auth was not called from the open callback.
Mikael Hallendal <micke@imendio.com>
parents: 227
diff changeset
  1104
void
704881ac7788 Fixed potential problem if auth was not called from the open callback.
Mikael Hallendal <micke@imendio.com>
parents: 227
diff changeset
  1105
lm_sasl_authenticate (LmSASL              *sasl,
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
  1106
                      LmAuthParameters    *auth_params,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1107
                      const gchar         *server,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1108
                      LmSASLResultHandler  handler)
255
704881ac7788 Fixed potential problem if auth was not called from the open callback.
Mikael Hallendal <micke@imendio.com>
parents: 227
diff changeset
  1109
{
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
  1110
    sasl->auth_params = lm_auth_parameters_ref (auth_params);
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
  1111
    sasl->server      = g_strdup (server);
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
  1112
    sasl->handler     = handler;
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
  1113
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1114
    sasl->challenge_cb = lm_message_handler_new (sasl_challenge_cb,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1115
                                                 sasl,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1116
                                                 NULL);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1117
    lm_connection_register_message_handler (sasl->connection,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1118
                                            sasl->challenge_cb,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1119
                                            LM_MESSAGE_TYPE_CHALLENGE,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1120
                                            LM_HANDLER_PRIORITY_FIRST);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 571
diff changeset
  1121
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1122
    sasl->success_cb = lm_message_handler_new (sasl_success_cb,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1123
                                               sasl,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1124
                                               NULL);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1125
    lm_connection_register_message_handler (sasl->connection,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1126
                                            sasl->success_cb,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1127
                                            LM_MESSAGE_TYPE_SUCCESS,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1128
                                            LM_HANDLER_PRIORITY_FIRST);
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
  1129
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1130
    sasl->failure_cb = lm_message_handler_new (sasl_failure_cb,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1131
                                               sasl,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1132
                                               NULL);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1133
    lm_connection_register_message_handler (sasl->connection,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1134
                                            sasl->failure_cb,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1135
                                            LM_MESSAGE_TYPE_FAILURE,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1136
                                            LM_HANDLER_PRIORITY_FIRST);
255
704881ac7788 Fixed potential problem if auth was not called from the open callback.
Mikael Hallendal <micke@imendio.com>
parents: 227
diff changeset
  1137
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1138
    if (sasl->features_received) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1139
        sasl_authenticate (sasl);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1140
    } else {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1141
        sasl->start_auth = TRUE;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1142
    }
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
  1143
}
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
  1144
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
  1145
void
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
  1146
lm_sasl_free (LmSASL *sasl)
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
  1147
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1148
    g_return_if_fail (sasl != NULL);
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 571
diff changeset
  1149
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
  1150
    if (sasl->auth_params) {
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
  1151
        lm_auth_parameters_unref (sasl->auth_params);
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
  1152
    }
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
  1153
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1154
    g_free (sasl->server);
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
  1155
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1156
    if (sasl->features_cb) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1157
        lm_connection_unregister_message_handler (sasl->connection,
607
e2bd14357c9a Some style fixes
Frank Zschockelt <lm@freakysoft.de>
parents: 571
diff changeset
  1158
                                                  sasl->features_cb,
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1159
                                                  LM_MESSAGE_TYPE_STREAM_FEATURES);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1160
    }
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
  1161
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1162
    if (sasl->challenge_cb) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1163
        lm_connection_unregister_message_handler (sasl->connection,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1164
                                                  sasl->challenge_cb,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1165
                                                  LM_MESSAGE_TYPE_CHALLENGE);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1166
    }
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
  1167
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1168
    if (sasl->success_cb) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1169
        lm_connection_unregister_message_handler (sasl->connection,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1170
                                                  sasl->success_cb,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1171
                                                  LM_MESSAGE_TYPE_SUCCESS);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1172
    }
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
  1173
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1174
    if (sasl->failure_cb) {
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1175
        lm_connection_unregister_message_handler (sasl->connection,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1176
                                                  sasl->failure_cb,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1177
                                                  LM_MESSAGE_TYPE_FAILURE);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1178
    }
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
  1179
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1180
    g_free (sasl);
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
  1181
}
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
  1182
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
  1183
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
  1184
LmAuthParameters *
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
  1185
lm_sasl_get_auth_params (LmSASL *sasl)
332
6b6ad42cd508 Support obsolete XEP-0078 (old-style jabber auth for XMPP1.0).
Senko Rasic <senko@phyrexia.lan>
parents: 321
diff changeset
  1186
{
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
  1187
    return sasl->auth_params;
332
6b6ad42cd508 Support obsolete XEP-0078 (old-style jabber auth for XMPP1.0).
Senko Rasic <senko@phyrexia.lan>
parents: 321
diff changeset
  1188
}
6b6ad42cd508 Support obsolete XEP-0078 (old-style jabber auth for XMPP1.0).
Senko Rasic <senko@phyrexia.lan>
parents: 321
diff changeset
  1189