loudmouth/lm-sasl.c
author Jelmer Vernooij <jelmer@samba.org>
Wed, 19 Nov 2008 09:09:13 +0100
changeset 563 33ffbface103
parent 540 72acfccdec86
child 564 db3e9ff448cb
permissions -rw-r--r--
Applied patch to add GSSAPI support to Loudmouth [#20] This patch adds optional suppor for SASL support through GSSAPI mechanism. Patch from Jelmer Vernooij. committer: Mikael Hallendal <micke@imendio.com>
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
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   115
sasl_gssapi_fail (LmSASL     *sasl, 
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
{
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   120
    guint32 err_major_status, err_minor_status;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   121
    guint32	msg_ctx = 0;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   122
    gss_buffer_desc major_status_string = GSS_C_EMPTY_BUFFER,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   123
                    minor_status_string = GSS_C_EMPTY_BUFFER;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   124
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   125
    err_major_status = gss_display_status (&err_minor_status, major_status,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   126
                                           GSS_C_GSS_CODE, GSS_C_NO_OID, 
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   127
                                           &msg_ctx, &major_status_string);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   128
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   129
    if (!GSS_ERROR(err_major_status))
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   130
        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
   131
                                               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
   132
                                               &msg_ctx, &minor_status_string);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   133
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   134
    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
   135
           (char *)major_status_string.value,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   136
           (char *)minor_status_string.value);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   137
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   138
    if (sasl->handler) {
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   139
        sasl->handler (sasl, sasl->connection,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   140
                       FALSE, "GSSAPI failure");
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   141
    }
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
    gss_release_buffer(&err_minor_status, &major_status_string);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   144
    gss_release_buffer(&err_minor_status, &minor_status_string);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   145
}
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
static gss_name_t
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   148
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
   149
{
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   150
    gss_buffer_desc token = GSS_C_EMPTY_BUFFER;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   151
    gss_name_t service_name = GSS_C_NO_NAME;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   152
    guint32 major_status, minor_status;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   153
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   154
    token.value	= g_strdup_printf ("xmpp@%s", sasl->server);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   155
    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
   156
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   157
    if (token.value == NULL) {
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   158
        return GSS_C_NO_NAME;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   159
    }
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   160
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   161
    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
   162
                                    GSS_C_NT_HOSTBASED_SERVICE,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   163
                                    &service_name);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   164
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   165
    if (GSS_ERROR(major_status))
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   166
    {
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   167
        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
   168
                          major_status, minor_status);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   169
        return GSS_C_NO_NAME;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   170
    }
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
    return service_name;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   173
}
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
static gboolean
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   176
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
   177
{
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   178
    gchar *response64;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   179
    gss_buffer_desc input_buffer_desc;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   180
    gss_buffer_t input_buffer;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   181
    gss_buffer_desc output_buffer_desc;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   182
    gss_buffer_t output_buffer;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   183
    guint32 major_status, minor_status;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   184
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   185
    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
   186
    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
   187
    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
   188
        return FALSE;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   189
    }
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   190
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   191
    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
   192
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   193
    input_buffer_desc.value = NULL;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   194
    input_buffer_desc.length = 0;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   195
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   196
    input_buffer = &input_buffer_desc;
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
    output_buffer_desc.value = NULL;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   199
    output_buffer_desc.length = 0;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   200
    output_buffer = &output_buffer_desc;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   201
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   202
    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
   203
                                         GSS_C_NO_CREDENTIAL,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   204
                                         &sasl->gss_ctx,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   205
                                         sasl->gss_service,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   206
                                         GSS_C_NO_OID,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   207
                                         GSS_C_MUTUAL_FLAG |
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   208
                                         GSS_C_REPLAY_FLAG |
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   209
                                         GSS_C_SEQUENCE_FLAG |
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   210
                                         GSS_C_INTEG_FLAG |
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   211
                                         GSS_C_CONF_FLAG,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   212
                                         0,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   213
                                         GSS_C_NO_CHANNEL_BINDINGS,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   214
                                         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
   215
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   216
    if (GSS_ERROR(major_status)) {
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   217
        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
   218
                          major_status, minor_status);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   219
        return FALSE;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   220
    }
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   221
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   222
    if (major_status != GSS_S_CONTINUE_NEEDED)
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   223
        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
   224
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   225
    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
   226
                                  (gsize) output_buffer_desc.length);
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
    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
   229
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   230
    g_free (response64);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   231
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   232
    return TRUE;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   233
}
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
static gboolean
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   236
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
   237
{
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   238
    const gchar *encoded;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   239
    gchar *response64;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   240
    gss_buffer_t input_buffer;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   241
    gss_buffer_desc input_buffer_desc;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   242
    gss_buffer_t output_buffer;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   243
    gss_buffer_desc output_buffer_desc;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   244
    guint32 major_status, minor_status;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   245
    gboolean result;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   246
    LmMessage *msg;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   247
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   248
    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
   249
    if (encoded == NULL) {
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   250
        input_buffer_desc.value = NULL;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   251
        input_buffer_desc.length = 0;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   252
    } else {
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   253
        input_buffer_desc.value = base64_decode (encoded,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   254
                                                 &input_buffer_desc.length);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   255
    }
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   256
    input_buffer = &input_buffer_desc;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   257
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   258
    output_buffer_desc.value = NULL;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   259
    output_buffer_desc.length = 0;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   260
    output_buffer = &output_buffer_desc;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   261
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   262
    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
   263
        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
   264
                                             GSS_C_NO_CREDENTIAL,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   265
                                             &sasl->gss_ctx,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   266
                                             sasl->gss_service,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   267
                                             GSS_C_NO_OID,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   268
                                             GSS_C_MUTUAL_FLAG |
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   269
                                             GSS_C_REPLAY_FLAG |
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   270
                                             GSS_C_SEQUENCE_FLAG |
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   271
                                             GSS_C_INTEG_FLAG |
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   272
                                             GSS_C_CONF_FLAG,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   273
                                             0,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   274
                                             GSS_C_NO_CHANNEL_BINDINGS,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   275
                                             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
   276
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   277
        if (GSS_ERROR(major_status)) {
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   278
            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
   279
                              major_status, minor_status);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   280
            return FALSE;
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
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   283
        if (major_status != GSS_S_CONTINUE_NEEDED)
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   284
            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
   285
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   286
        major_status = gss_release_buffer (&minor_status, input_buffer);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   287
        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
   288
            return FALSE;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   289
    } 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
   290
        gchar *features;
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_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
   293
                                   input_buffer, output_buffer,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   294
                                   NULL, NULL);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   295
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   296
        if (GSS_ERROR(major_status)) {
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   297
            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
   298
                              major_status, minor_status);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   299
            return FALSE;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   300
        }
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   301
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   302
        major_status = gss_release_buffer (&minor_status, input_buffer);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   303
        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
   304
            return FALSE;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   305
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   306
        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
   307
        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
   308
            return FALSE;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   309
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   310
        input_buffer_desc.length = 4 + strlen(sasl->username);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   311
        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
   312
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   313
        features[0] = 1;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   314
        features[1] = 0xFF;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   315
        features[2] = 0xFF;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   316
        features[3] = 0xFF;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   317
        strcpy(features+4, sasl->username);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   318
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   319
        input_buffer_desc.value = features;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   320
        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
   321
                                 0, /* Just integrity checking here */
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   322
                                 GSS_C_QOP_DEFAULT,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   323
                                 input_buffer,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   324
                                 NULL,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   325
                                 output_buffer);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   326
        g_free (features);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   327
        if (GSS_ERROR(major_status)) {
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   328
            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
   329
                              major_status, minor_status);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   330
            return FALSE;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   331
        }
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   332
    } else {
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   333
        g_assert_not_reached ();
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   334
    }
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   335
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   336
    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
   337
    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
   338
                                    "xmlns", XMPP_NS_SASL_AUTH,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   339
                                    NULL);
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
    if (output_buffer_desc.value != NULL) {
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   342
        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
   343
                                      (gsize) output_buffer_desc.length);
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
    } else {
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   346
        response64 = g_strdup ("");
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   347
    }
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   348
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   349
    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
   350
    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
   351
        g_free (response64);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   352
        lm_message_unref (msg);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   353
        return FALSE;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   354
    }
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   355
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   356
    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
   357
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   358
    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
   359
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
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   363
    if (!result) {
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   364
        g_warning ("Failed to send SASL response\n");
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   365
        return FALSE;
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
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   368
    return TRUE;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   369
}
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   370
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   371
static gboolean
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   372
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
   373
{
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   374
    OM_uint32 major_status, minor_status;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   375
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   376
    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
   377
        major_status = gss_release_name (&minor_status, &sasl->gss_service);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   378
    if (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
   379
        major_status = gss_delete_sec_context (&minor_status, &sasl->gss_ctx,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   380
                                               GSS_C_NO_BUFFER);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   381
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   382
    return TRUE;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   383
}
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   384
#endif
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   385
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   386
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   387
/* DIGEST-MD5 mechanism code from libgibber */
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   388
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   389
static gchar *
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   390
sasl_strndup_unescaped (const gchar *str, gsize len) 
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   391
{
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
   392
    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
   393
    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
   394
    gchar       *ret;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   395
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
   396
    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
   397
    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
   398
        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
   399
        *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
   400
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   401
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
   402
    return ret;
216
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
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   405
static GHashTable *
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   406
sasl_digest_md5_challenge_to_hash (const gchar * challenge)
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   407
{
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
   408
    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
   409
    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
   410
    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
   411
    GHashTable  *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
   412
    
cdd6a0c5b439 Went 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
    result = g_hash_table_new_full (g_str_hash, g_str_equal, 
cdd6a0c5b439 Went 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
                                    g_free, g_free);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   415
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
   416
    do { 
cdd6a0c5b439 Went 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
        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
   418
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
   419
        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
   420
        for (; *c != '\0' && *c != '='; c++);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   421
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
   422
        if (*c == '\0' || c == keystart) goto error;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   423
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
   424
        keyend = 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
   425
        c++;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   426
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
   427
        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
   428
            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
   429
            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
   430
            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
   431
            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
   432
            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
   433
            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
   434
        } 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
   435
            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
   436
            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
   437
            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
   438
            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
   439
        }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   440
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
   441
        key = g_strndup (keystart, keyend - keystart);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   442
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
   443
        g_hash_table_insert (result, key, val);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   444
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
   445
        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
   446
    } while (*c != '\0');
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   447
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
   448
    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
   449
 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
   450
    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
   451
           "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
   452
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
   453
    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
   454
    return NULL;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   455
}
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   456
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   457
static gchar *
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   458
sasl_md5_hex_hash (gchar *value, gsize len) 
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
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
    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
   461
    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
   462
    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
   463
    int          i;
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   464
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
   465
    str = g_string_sized_new (32);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   466
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
   467
    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
   468
    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
   469
    md5_finish (&md5_calc, digest_md5);
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   470
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
   471
    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
   472
        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
   473
    }
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
    return g_string_free (str, FALSE);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   476
}
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   477
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   478
static gchar *
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   479
sasl_digest_md5_generate_cnonce(void)
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   480
{
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
   481
    /* 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
   482
     * at least 64 bits of entropy */
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   483
#define NR 8
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
   484
    guint32 n[NR]; 
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   485
    int i;
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   486
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
   487
    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
   488
        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
   489
    }
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   490
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
   491
    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
   492
}
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   493
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   494
static gchar *
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   495
sasl_md5_prepare_response (LmSASL *sasl, GHashTable *challenge)
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   496
{
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
   497
    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
   498
    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
   499
    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
   500
    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
   501
    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
   502
    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
   503
    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
   504
    gsize        len;
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
    response = g_string_new ("");
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   507
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   508
    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
   509
        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
   510
               "%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
   511
        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
   512
            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
   513
                           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
   514
        }
cdd6a0c5b439 Went 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
        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
   516
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   517
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
   518
    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
   519
    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
   520
        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
   521
               "%s: server didn't provide a nonce in the 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
   522
               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
   523
        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
   524
            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
   525
                           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
   526
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   527
        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
   528
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   529
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
   530
    cnonce = sasl_digest_md5_generate_cnonce ();
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   531
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
   532
    /* 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
   533
    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
   534
    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
   535
        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
   536
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   537
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
   538
    /* 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
   539
    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
   540
    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
   541
    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
   542
    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
   543
    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
   544
    /* 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
   545
    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
   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
    tmp = g_strdup_printf ("%s:%s:%s", 
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   548
                           lm_auth_parameters_get_username (sasl->auth_params), 
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   549
                           realm, lm_auth_parameters_get_password (sasl->auth_params));
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   550
        
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
   551
    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
   552
    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
   553
    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
   554
    g_free (tmp);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   555
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
   556
    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
   557
    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
   558
    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
   559
    a1h = sasl_md5_hex_hash (a1, len);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   560
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
   561
    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
   562
    a2h = sasl_md5_hex_hash (a2, strlen(a2));
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   563
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
   564
    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
   565
                          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
   566
    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
   567
    g_string_append_printf (response, ",response=%s", kdh);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   568
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
   569
    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
   570
    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
   571
    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
   572
    g_free (a2h);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   573
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
   574
    /* 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
   575
    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
   576
    a2h = sasl_md5_hex_hash (a2, strlen(a2));
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   577
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
   578
    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
   579
    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
   580
    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
   581
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
   582
    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
   583
    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
   584
    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
   585
    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
   586
    g_free (kd);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   587
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
   588
 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
   589
    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
   590
    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
   591
        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
   592
    } 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
   593
        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
   594
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   595
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
   596
 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
   597
    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
   598
    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
   599
    goto out;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   600
}
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   601
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   602
static gboolean
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   603
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
   604
{
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
   605
    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
   606
    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
   607
    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
   608
    int        result;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   609
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   610
    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
   611
    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
   612
        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
   613
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   614
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
   615
    response64 = g_base64_encode ((const guchar *) 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
   616
                                  (gsize) strlen(response));
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   617
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
   618
    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
   619
    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
   620
                                    "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
   621
                                    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
   622
    lm_message_node_set_value (msg->node, response64);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   623
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
   624
    result = lm_connection_send (sasl->connection, msg, NULL);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   625
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
    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
   627
    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
   628
    lm_message_unref (msg);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   629
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
   630
    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
   631
        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
   632
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   633
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
   634
    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
   635
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
   636
    return TRUE;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   637
}
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   638
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   639
static gboolean
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   640
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
   641
{
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
   642
    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
   643
    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
   644
    int          result;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   645
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
   646
    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
   647
    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
   648
        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
   649
               "%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
   650
               G_STRFUNC);
224
447f16217278 Use g_log instead of g_debug
Mikael Hallendal <micke@imendio.com>
parents: 216
diff changeset
   651
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
   652
        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
   653
            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
   654
                           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
   655
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   656
        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
   657
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   658
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
   659
    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
   660
        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
   661
               "%s: server sent an invalid reply (rspauth not matching)\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
   662
               G_STRFUNC);
224
447f16217278 Use g_log instead of g_debug
Mikael Hallendal <micke@imendio.com>
parents: 216
diff changeset
   663
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
   664
        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
   665
            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
   666
                           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
   667
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   668
        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
   669
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   670
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
   671
    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
   672
    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
   673
                                    "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
   674
                                    NULL);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   675
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
   676
    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
   677
    lm_message_unref (msg);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
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 (!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
   680
        g_warning ("Failed to send SASL response\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
   681
        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
   682
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   683
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
   684
    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
   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
    return TRUE;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   687
}
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   688
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   689
static gboolean
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   690
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
   691
{
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
   692
    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
   693
    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
   694
    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
   695
    GHashTable  *h;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   696
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
    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
   698
    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
   699
        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
   700
               "%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
   701
        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
   702
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   703
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
   704
    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
   705
    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
   706
    g_free(challenge);
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
    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
   709
        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
   710
               "%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
   711
        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
   712
            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
   713
                           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
   714
        }
cdd6a0c5b439 Went 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
        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
   716
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   717
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
   718
    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
   719
    case 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
   720
        sasl_digest_md5_send_initial_response (sasl, 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
   721
        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
   722
    case 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
   723
        sasl_digest_md5_check_server_response (sasl, 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
   724
        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
   725
    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
   726
        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
   727
               "%s: server sent a challenge at the wrong time", 
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   728
               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
   729
        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
   730
            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
   731
                           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
   732
        }
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
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
        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
   735
    } 
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   736
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
    g_hash_table_destroy(h);
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   738
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
   739
    return TRUE;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   740
}
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   741
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   742
static LmHandlerResult
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   743
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
   744
                   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
   745
                   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
   746
                   gpointer          user_data)
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   747
{
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
   748
    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
   749
    const gchar *ns;
224
447f16217278 Use g_log instead of g_debug
Mikael Hallendal <micke@imendio.com>
parents: 216
diff changeset
   750
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
   751
    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
   752
    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
   753
        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
   754
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   755
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
   756
    sasl = (LmSASL *) user_data;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   757
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
   758
    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
   759
    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
   760
        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
   761
               "%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
   762
               G_STRFUNC);
224
447f16217278 Use g_log instead of g_debug
Mikael Hallendal <micke@imendio.com>
parents: 216
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
        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
   765
            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
   766
                           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
   767
        }
cdd6a0c5b439 Went 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
        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
   769
    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
   770
        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
   771
        break;
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   772
#ifdef HAVE_GSSAPI
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   773
    case AUTH_TYPE_GSSAPI:
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   774
        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
   775
        break;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   776
#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
   777
    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
   778
        g_warning ("Wrong 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
   779
        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
   780
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   781
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
    return LM_HANDLER_RESULT_REMOVE_MESSAGE;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   783
}
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   784
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   785
static LmHandlerResult
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   786
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
   787
                 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
   788
                 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
   789
                 gpointer          user_data)
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   790
{
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
   791
    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
   792
    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
   793
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   794
    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
   795
    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
   796
        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
   797
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   798
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
   799
    sasl = (LmSASL *) user_data;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   800
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
   801
    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
   802
    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
   803
        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
   804
            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
   805
                   "%s: server sent success before finishing 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
   806
                   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
   807
            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
   808
                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
   809
                               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
   810
            }
cdd6a0c5b439 Went 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
        }
cdd6a0c5b439 Went 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
        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
   813
    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
   814
        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
   815
            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
   816
            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
   817
                   "%s: server sent success before finishing 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
   818
                   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
   819
            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
   820
                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
   821
                               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
   822
            }
cdd6a0c5b439 Went 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
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   824
        break;
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   825
#ifdef HAVE_GSSAPI
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   826
    case AUTH_TYPE_GSSAPI:
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   827
        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
   828
            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
   829
            sasl_gssapi_finish(sasl, message->node);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   830
            g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SASL, 
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   831
                   "%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
   832
                   G_STRFUNC);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   833
            if (sasl->handler) {
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   834
                sasl->handler (sasl, sasl->connection,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   835
                               FALSE, "server error");
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   836
            }
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   837
        }
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   838
        break;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   839
#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
   840
    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
   841
        g_warning ("Wrong 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
   842
        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
   843
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   844
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
   845
    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
   846
           "%s: SASL authentication successful", G_STRFUNC);
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   847
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
   848
    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
   849
        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
   850
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   851
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
   852
    return LM_HANDLER_RESULT_REMOVE_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
   853
    
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   854
}
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   855
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   856
static LmHandlerResult
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   857
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
   858
                 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
   859
                 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
   860
                 gpointer          user_data)
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   861
{
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
   862
    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
   863
    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
   864
    const gchar *reason = "unknown 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
   865
    
cdd6a0c5b439 Went 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
    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
   867
    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
   868
        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
   869
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   870
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
   871
    sasl = (LmSASL *) user_data;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   872
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
   873
    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
   874
        const gchar *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
   875
        
cdd6a0c5b439 Went 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
        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
   877
        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
   878
            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
   879
        }
cdd6a0c5b439 Went 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
    }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   881
    
cdd6a0c5b439 Went 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
    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
   883
           "%s: SASL authentication failed: %s", G_STRFUNC, reason);
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   884
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
   885
    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
   886
        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
   887
    }
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
    return LM_HANDLER_RESULT_REMOVE_MESSAGE;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   890
}
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   891
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   892
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   893
static gboolean
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   894
sasl_start (LmSASL *sasl)
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   895
{
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
   896
    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
   897
    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
   898
    const char *mech = NULL;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   899
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
   900
    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
   901
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
   902
    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
   903
        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
   904
        gchar   *cstr;
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   905
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
   906
        str = g_string_new ("");
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   907
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
   908
        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
   909
        sasl->state = SASL_AUTH_STATE_PLAIN_STARTED;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   910
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   911
        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
   912
            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
   913
                   "%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
   914
                   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
   915
            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
   916
                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
   917
            }
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   918
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
   919
            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
   920
        }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
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
        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
   923
        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
   924
        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
   925
        g_string_append (str, lm_auth_parameters_get_password (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
   926
        cstr = g_base64_encode ((const guchar *) str->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
   927
                                (gsize) str->len);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   928
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
   929
        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
   930
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
   931
        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
   932
        g_free (cstr);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   933
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
   934
        /* 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
   935
        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
   936
                                        "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
   937
                                        "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
   938
                                        NULL);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   939
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
    } 
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   941
    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
   942
        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
   943
        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
   944
    }
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   945
#ifdef HAVE_GSSAPI
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   946
    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
   947
        mech = "GSSAPI";
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   948
        sasl_gssapi_start(sasl, auth_msg->node);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   949
    }
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   950
#endif
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   951
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
   952
    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
   953
                                    "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
   954
                                    "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
   955
                                    NULL);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
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
    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
   958
    lm_message_unref (auth_msg);
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   959
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
   960
    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
   961
        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
   962
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   963
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
   964
    return TRUE;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   965
}
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   966
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   967
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
   968
sasl_set_auth_type (LmSASL *sasl, LmMessageNode *mechanisms)
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   969
{
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
   970
    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
   971
    const gchar   *ns;
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
    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
   974
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
   975
    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
   976
    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
   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
    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
   981
        const gchar *name;
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   982
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
   983
        name = lm_message_node_get_value (m);
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   984
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
   985
        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
   986
            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
   987
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   988
        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
   989
            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
   990
            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
   991
        }
cdd6a0c5b439 Went 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 (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
   993
            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
   994
            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
   995
        }
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   996
        if (strcmp (name, "GSSAPI") == 0) {
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   997
            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
   998
            continue;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   999
        }
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
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
        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
  1002
               "%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
  1003
    }
255
704881ac7788 Fixed potential problem if auth was not called from the open callback.
Mikael Hallendal <micke@imendio.com>
parents: 227
diff changeset
  1004
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
  1005
    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
  1006
}
704881ac7788 Fixed potential problem if auth was not called from the open callback.
Mikael Hallendal <micke@imendio.com>
parents: 227
diff changeset
  1007
704881ac7788 Fixed potential problem if auth was not called from the open callback.
Mikael Hallendal <micke@imendio.com>
parents: 227
diff changeset
  1008
static gboolean
704881ac7788 Fixed potential problem if auth was not called from the open callback.
Mikael Hallendal <micke@imendio.com>
parents: 227
diff changeset
  1009
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
  1010
{
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
  1011
    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
  1012
        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
  1013
               "%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
  1014
               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
  1015
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
  1016
        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
  1017
    }
255
704881ac7788 Fixed potential problem if auth was not called from the open callback.
Mikael Hallendal <micke@imendio.com>
parents: 227
diff changeset
  1018
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
  1019
    /* Prefer GSSAPI if available */
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
  1020
#ifdef HAVE_GSSAPI
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
  1021
    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
  1022
        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
  1023
        return sasl_start (sasl);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
  1024
    }
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
  1025
#endif
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
  1026
    /* Otherwise prefer DIGEST */
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
  1027
    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
  1028
        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
  1029
        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
  1030
    }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1031
    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
  1032
        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
  1033
        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
  1034
    } 
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1035
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
  1036
    return FALSE;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1037
}
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1038
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1039
static LmHandlerResult
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
  1040
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
  1041
                  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
  1042
                  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
  1043
                  gpointer          user_data)
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1044
{
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
  1045
    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
  1046
    LmSASL        *sasl;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1047
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
  1048
    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
  1049
    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
  1050
    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
  1051
        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
  1052
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1053
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
  1054
    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
  1055
    sasl->features_received = TRUE;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1056
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
    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
  1058
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
  1059
    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
  1060
        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
  1061
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1062
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
  1063
    return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1064
}
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1065
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
  1066
LmSASL *
255
704881ac7788 Fixed potential problem if auth was not called from the open callback.
Mikael Hallendal <micke@imendio.com>
parents: 227
diff changeset
  1067
lm_sasl_new (LmConnection *connection)
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
  1068
{
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
  1069
    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
  1070
    
cdd6a0c5b439 Went 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 = g_new0 (LmSASL, 1);
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->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
  1074
    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
  1075
    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
  1076
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
  1077
    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
  1078
                                                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
  1079
                                                NULL);
255
704881ac7788 Fixed potential problem if auth was not called from the open callback.
Mikael Hallendal <micke@imendio.com>
parents: 227
diff changeset
  1080
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
  1081
    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
  1082
                                            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
  1083
                                            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
  1084
                                            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
  1085
    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
  1086
}
704881ac7788 Fixed potential problem if auth was not called from the open callback.
Mikael Hallendal <micke@imendio.com>
parents: 227
diff changeset
  1087
704881ac7788 Fixed potential problem if auth was not called from the open callback.
Mikael Hallendal <micke@imendio.com>
parents: 227
diff changeset
  1088
void
704881ac7788 Fixed potential problem if auth was not called from the open callback.
Mikael Hallendal <micke@imendio.com>
parents: 227
diff changeset
  1089
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
  1090
                      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
  1091
                      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
  1092
                      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
  1093
{
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
  1094
    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
  1095
    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
  1096
    sasl->handler     = handler;
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
  1097
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
  1098
    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
  1099
                                                 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
  1100
                                                 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
  1101
    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
  1102
                                            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
  1103
                                            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
  1104
                                            LM_HANDLER_PRIORITY_FIRST);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1105
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1106
    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
  1107
                                               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
  1108
                                               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
  1109
    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
  1110
                                            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
  1111
                                            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
  1112
                                            LM_HANDLER_PRIORITY_FIRST);
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->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
  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->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
  1119
                                            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
  1120
                                            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
  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
    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
  1123
        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
  1124
    } 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
  1125
        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
  1126
    }
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
  1127
}
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
  1128
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
  1129
void
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
  1130
lm_sasl_free (LmSASL *sasl)
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
  1131
{
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
  1132
    g_return_if_fail (sasl != NULL);
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
  1133
    
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
  1134
    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
  1135
        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
  1136
    }
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
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
    g_free (sasl->server);
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
  1139
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
  1140
    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
  1141
        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
  1142
                                                  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
  1143
                                                  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
  1144
    }
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
  1145
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
  1146
    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
  1147
        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
  1148
                                                  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
  1149
                                                  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
  1150
    }
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
  1151
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
  1152
    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
  1153
        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
  1154
                                                  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
  1155
                                                  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
  1156
    }
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
  1157
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
  1158
    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
  1159
        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
  1160
                                                  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
  1161
                                                  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
  1162
    }
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
  1163
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
  1164
    g_free (sasl);
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
  1165
}
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
  1166
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
  1167
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
  1168
LmAuthParameters *
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
  1169
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
  1170
{
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
  1171
    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
  1172
}
6b6ad42cd508 Support obsolete XEP-0078 (old-style jabber auth for XMPP1.0).
Senko Rasic <senko@phyrexia.lan>
parents: 321
diff changeset
  1173