loudmouth/lm-sasl.c
author Jayson Vantuyl <jvantuyl@engineyard.com>
Wed, 25 Mar 2009 11:28:18 -0700
changeset 596 9096d2549372
parent 571 6fb1c4046db7
child 607 e2bd14357c9a
permissions -rw-r--r--
Removed Dangerous Instructions
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
{
564
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   120
    guint32         err_major_status;
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   121
    guint32         err_minor_status;
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   122
    guint32         msg_ctx = 0;
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   123
    gss_buffer_desc major_status_string = GSS_C_EMPTY_BUFFER;
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   124
    gss_buffer_desc minor_status_string = GSS_C_EMPTY_BUFFER;
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   125
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   126
    err_major_status = gss_display_status (&err_minor_status, major_status,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   127
                                           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
   128
                                           &msg_ctx, &major_status_string);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   129
564
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   130
    if (!GSS_ERROR(err_major_status)) {
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   131
        err_major_status = gss_display_status (&err_minor_status, minor_status,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   132
                                               GSS_C_MECH_CODE, GSS_C_NULL_OID,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   133
                                               &msg_ctx, &minor_status_string);
564
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   134
    }
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   135
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   136
    g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_SASL, "GSSAPI: %s: %s, %s", message,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   137
           (char *)major_status_string.value,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   138
           (char *)minor_status_string.value);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   139
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   140
    if (sasl->handler) {
564
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   141
        sasl->handler (sasl, sasl->connection, FALSE, "GSSAPI failure");
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   142
    }
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   143
564
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   144
    gss_release_buffer (&err_minor_status, &major_status_string);
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   145
    gss_release_buffer (&err_minor_status, &minor_status_string);
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   146
}
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   147
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   148
static gss_name_t
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   149
sasl_gssapi_get_creds (LmSASL *sasl)
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   150
{
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   151
    gss_buffer_desc token = GSS_C_EMPTY_BUFFER;
564
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   152
    gss_name_t      service_name = GSS_C_NO_NAME;
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   153
    guint32         major_status;
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   154
    guint32         minor_status;
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   155
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   156
    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
   157
    token.length = strlen ((char *)token.value);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   158
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   159
    if (token.value == NULL) {
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   160
        return GSS_C_NO_NAME;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   161
    }
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   162
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   163
    major_status = gss_import_name (&minor_status, &token,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   164
                                    GSS_C_NT_HOSTBASED_SERVICE,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   165
                                    &service_name);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   166
564
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   167
    if (GSS_ERROR(major_status)) {
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   168
        sasl_gssapi_fail (sasl, "while obtaining service principal",
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   169
                          major_status, minor_status);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   170
        return GSS_C_NO_NAME;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   171
    }
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   172
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   173
    return service_name;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   174
}
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   175
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   176
static gboolean
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   177
sasl_gssapi_start (LmSASL *sasl, LmMessageNode *node)
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   178
{
564
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   179
    gchar           *response64;
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   180
    gss_buffer_desc  input_buffer_desc;
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   181
    gss_buffer_t     input_buffer;
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   182
    gss_buffer_desc  output_buffer_desc;
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   183
    gss_buffer_t     output_buffer;
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   184
    guint32          major_status;
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   185
    guint32          minor_status;
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   186
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   187
    sasl->gss_ctx = GSS_C_NO_CONTEXT;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   188
    sasl->gss_service = sasl_gssapi_get_creds (sasl);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   189
    if (sasl->gss_service == GSS_C_NO_NAME) {
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   190
        return FALSE;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   191
    }
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   192
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   193
    sasl->state = SASL_AUTH_STATE_GSSAPI_STARTED;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   194
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   195
    input_buffer_desc.value = NULL;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   196
    input_buffer_desc.length = 0;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   197
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   198
    input_buffer = &input_buffer_desc;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   199
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   200
    output_buffer_desc.value = NULL;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   201
    output_buffer_desc.length = 0;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   202
    output_buffer = &output_buffer_desc;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   203
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   204
    major_status = gss_init_sec_context (&minor_status,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   205
                                         GSS_C_NO_CREDENTIAL,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   206
                                         &sasl->gss_ctx,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   207
                                         sasl->gss_service,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   208
                                         GSS_C_NO_OID,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   209
                                         GSS_C_MUTUAL_FLAG |
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   210
                                         GSS_C_REPLAY_FLAG |
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   211
                                         GSS_C_SEQUENCE_FLAG |
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   212
                                         GSS_C_INTEG_FLAG |
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   213
                                         GSS_C_CONF_FLAG,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   214
                                         0,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   215
                                         GSS_C_NO_CHANNEL_BINDINGS,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   216
                                         input_buffer, NULL, output_buffer, NULL, NULL);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   217
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   218
    if (GSS_ERROR(major_status)) {
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   219
        sasl_gssapi_fail (sasl, "during challenge/response",
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   220
                          major_status, minor_status);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   221
        return FALSE;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   222
    }
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   223
564
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   224
    if (major_status != GSS_S_CONTINUE_NEEDED) {
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   225
        sasl->state = SASL_AUTH_STATE_GSSAPI_SENT_AUTH_RESPONSE;
564
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   226
    }
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   227
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   228
    response64 = g_base64_encode ((const guchar *) output_buffer_desc.value,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   229
                                  (gsize) output_buffer_desc.length);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   230
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   231
    lm_message_node_set_value (node, response64);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   232
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   233
    g_free (response64);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   234
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   235
    return TRUE;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   236
}
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   237
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   238
static gboolean
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   239
sasl_gssapi_handle_challenge (LmSASL *sasl, LmMessageNode *node)
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   240
{
564
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   241
    const gchar     *encoded;
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   242
    gchar           *response64;
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   243
    gss_buffer_t     input_buffer;
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   244
    gss_buffer_desc  input_buffer_desc;
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   245
    gss_buffer_t     output_buffer;
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   246
    gss_buffer_desc  output_buffer_desc;
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   247
    guint32          major_status;
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   248
    guint32          minor_status;
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   249
    gboolean         result;
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   250
    LmMessage       *msg;
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   251
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   252
    encoded = lm_message_node_get_value (node);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   253
    if (encoded == NULL) {
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   254
        input_buffer_desc.value = NULL;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   255
        input_buffer_desc.length = 0;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   256
    } else {
571
6fb1c4046db7 Fixed compile when GSSAPI support is enabled. [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 564
diff changeset
   257
        input_buffer_desc.value = g_base64_decode (encoded,
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   258
                                                 &input_buffer_desc.length);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   259
    }
564
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   260
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   261
    input_buffer = &input_buffer_desc;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   262
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   263
    output_buffer_desc.value = NULL;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   264
    output_buffer_desc.length = 0;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   265
    output_buffer = &output_buffer_desc;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   266
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   267
    if (sasl->state == SASL_AUTH_STATE_GSSAPI_STARTED) {
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   268
        major_status = gss_init_sec_context (&minor_status,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   269
                                             GSS_C_NO_CREDENTIAL,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   270
                                             &sasl->gss_ctx,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   271
                                             sasl->gss_service,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   272
                                             GSS_C_NO_OID,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   273
                                             GSS_C_MUTUAL_FLAG |
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   274
                                             GSS_C_REPLAY_FLAG |
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   275
                                             GSS_C_SEQUENCE_FLAG |
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   276
                                             GSS_C_INTEG_FLAG |
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   277
                                             GSS_C_CONF_FLAG,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   278
                                             0,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   279
                                             GSS_C_NO_CHANNEL_BINDINGS,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   280
                                             input_buffer, NULL, output_buffer, NULL, NULL);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   281
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   282
        if (GSS_ERROR(major_status)) {
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   283
            sasl_gssapi_fail (sasl, "during challenge/response",
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   284
                              major_status, minor_status);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   285
            return FALSE;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   286
        }
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   287
564
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   288
        if (major_status != GSS_S_CONTINUE_NEEDED) {
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   289
            sasl->state = SASL_AUTH_STATE_GSSAPI_SENT_AUTH_RESPONSE;
564
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   290
        }
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   291
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   292
        major_status = gss_release_buffer (&minor_status, input_buffer);
564
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   293
        if (major_status != GSS_S_COMPLETE) {
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   294
            return FALSE;
564
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   295
        }
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   296
    } else if (sasl->state == SASL_AUTH_STATE_GSSAPI_SENT_AUTH_RESPONSE) {
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   297
        gchar *features;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   298
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   299
        major_status = gss_unwrap (&minor_status, sasl->gss_ctx,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   300
                                   input_buffer, output_buffer,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   301
                                   NULL, NULL);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   302
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   303
        if (GSS_ERROR(major_status)) {
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   304
            sasl_gssapi_fail (sasl, "while unwrapping server capabilities",
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   305
                              major_status, minor_status);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   306
            return FALSE;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   307
        }
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   308
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   309
        major_status = gss_release_buffer (&minor_status, input_buffer);
564
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   310
        if (major_status != GSS_S_COMPLETE) {
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   311
            return FALSE;
564
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   312
        }
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   313
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   314
        major_status = gss_release_buffer (&minor_status, output_buffer);
564
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   315
        if (major_status != GSS_S_COMPLETE) {
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   316
            return FALSE;
564
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   317
        }
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   318
571
6fb1c4046db7 Fixed compile when GSSAPI support is enabled. [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 564
diff changeset
   319
        input_buffer_desc.length = 4 + strlen(lm_auth_parameters_get_username (sasl->auth_params));
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   320
        features = g_malloc (input_buffer_desc.length);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   321
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   322
        features[0] = 1;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   323
        features[1] = 0xFF;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   324
        features[2] = 0xFF;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   325
        features[3] = 0xFF;
571
6fb1c4046db7 Fixed compile when GSSAPI support is enabled. [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 564
diff changeset
   326
        strcpy(features+4, lm_auth_parameters_get_username (sasl->auth_params));
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   327
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   328
        input_buffer_desc.value = features;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   329
        major_status = gss_wrap (&minor_status, sasl->gss_ctx,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   330
                                 0, /* Just integrity checking here */
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   331
                                 GSS_C_QOP_DEFAULT,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   332
                                 input_buffer,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   333
                                 NULL,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   334
                                 output_buffer);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   335
        g_free (features);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   336
        if (GSS_ERROR(major_status)) {
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   337
            sasl_gssapi_fail (sasl, "while wrapping required features",
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   338
                              major_status, minor_status);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   339
            return FALSE;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   340
        }
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   341
    } else {
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   342
        g_assert_not_reached ();
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   343
    }
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   344
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   345
    msg = lm_message_new (NULL, LM_MESSAGE_TYPE_RESPONSE);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   346
    lm_message_node_set_attributes (msg->node,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   347
                                    "xmlns", XMPP_NS_SASL_AUTH,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   348
                                    NULL);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   349
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   350
    if (output_buffer_desc.value != NULL) {
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   351
        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
   352
                                      (gsize) output_buffer_desc.length);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   353
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   354
    } else {
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   355
        response64 = g_strdup ("");
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   356
    }
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   357
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   358
    major_status = gss_release_buffer (&minor_status, output_buffer);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   359
    if (major_status != GSS_S_COMPLETE) {
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   360
        g_free (response64);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   361
        lm_message_unref (msg);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   362
        return FALSE;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   363
    }
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   364
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   365
    lm_message_node_set_value (msg->node, response64);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   366
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   367
    result = lm_connection_send (sasl->connection, msg, NULL);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   368
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   369
    g_free (response64);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   370
    lm_message_unref (msg);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   371
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   372
    if (!result) {
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   373
        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
   374
        return FALSE;
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
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   377
    return TRUE;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   378
}
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   379
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   380
static gboolean
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   381
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
   382
{
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   383
    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
   384
564
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   385
    if (sasl->gss_service != GSS_C_NO_NAME) {
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   386
        major_status = gss_release_name (&minor_status, &sasl->gss_service);
564
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   387
    } 
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   388
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   389
    if (sasl->gss_ctx != GSS_C_NO_CONTEXT) {
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   390
        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
   391
                                               GSS_C_NO_BUFFER);
564
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   392
    }
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   393
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   394
    return TRUE;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   395
}
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   396
#endif
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   397
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   398
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   399
/* DIGEST-MD5 mechanism code from libgibber */
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   400
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   401
static gchar *
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   402
sasl_strndup_unescaped (const gchar *str, gsize len) 
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   403
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   404
    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
   405
    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
   406
    gchar       *ret;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
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
    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
   409
    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
   410
        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
   411
        *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
   412
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   413
518
cdd6a0c5b439 Went 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
    return ret;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   415
}
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   416
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   417
static GHashTable *
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   418
sasl_digest_md5_challenge_to_hash (const gchar * challenge)
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   419
{
518
cdd6a0c5b439 Went 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
    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
   421
    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
   422
    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
   423
    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
   424
    
cdd6a0c5b439 Went 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
    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
   426
                                    g_free, g_free);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   427
518
cdd6a0c5b439 Went 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
    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
   429
        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
   430
518
cdd6a0c5b439 Went 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
        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
   432
        for (; *c != '\0' && *c != '='; c++);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   433
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   434
        if (*c == '\0' || c == keystart) goto error;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   435
518
cdd6a0c5b439 Went 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
        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
   437
        c++;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   438
518
cdd6a0c5b439 Went 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
        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
   440
            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
   441
            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
   442
            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
   443
            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
   444
            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
   445
            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
        } 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
   447
            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
   448
            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
   449
            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
   450
            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
   451
        }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
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
        key = g_strndup (keystart, keyend - keystart);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   454
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   455
        g_hash_table_insert (result, key, val);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   456
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   457
        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
   458
    } while (*c != '\0');
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   459
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   460
    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
   461
 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
   462
    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
   463
           "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
   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
    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
   466
    return NULL;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   467
}
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   468
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   469
static gchar *
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   470
sasl_md5_hex_hash (gchar *value, gsize len) 
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   471
{
518
cdd6a0c5b439 Went 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
    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
   473
    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
   474
    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
   475
    int          i;
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   476
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   477
    str = g_string_sized_new (32);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   478
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   479
    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
   480
    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
   481
    md5_finish (&md5_calc, digest_md5);
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   482
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   483
    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
   484
        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
   485
    }
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
    return g_string_free (str, FALSE);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   488
}
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   489
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   490
static gchar *
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   491
sasl_digest_md5_generate_cnonce(void)
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   492
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   493
    /* 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
   494
     * at least 64 bits of entropy */
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   495
#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
   496
    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
   497
    int i;
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   498
518
cdd6a0c5b439 Went 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
    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
   500
        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
   501
    }
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   502
518
cdd6a0c5b439 Went 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
    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
   504
}
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   505
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   506
static gchar *
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   507
sasl_md5_prepare_response (LmSASL *sasl, GHashTable *challenge)
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   508
{
518
cdd6a0c5b439 Went 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
    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
   510
    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
   511
    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
   512
    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
   513
    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
   514
    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
   515
    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
   516
    gsize        len;
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
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
    response = g_string_new ("");
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   519
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   520
    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
   521
        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
   522
               "%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
   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, "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
   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
    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
   531
    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
   532
        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
   533
               "%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
   534
               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
   535
        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
   536
            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
   537
                           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
   538
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   539
        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
   540
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   541
518
cdd6a0c5b439 Went 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
    cnonce = sasl_digest_md5_generate_cnonce ();
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   543
518
cdd6a0c5b439 Went 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 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
   545
    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
   546
    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
   547
        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
   548
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   549
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   550
    /* 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
   551
    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
   552
    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
   553
    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
   554
    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
   555
    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
   556
    /* 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
   557
    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
   558
518
cdd6a0c5b439 Went 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
    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
   560
                           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
   561
                           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
   562
        
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   563
    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
   564
    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
   565
    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
   566
    g_free (tmp);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   567
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   568
    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
   569
    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
   570
    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
   571
    a1h = sasl_md5_hex_hash (a1, len);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   572
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   573
    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
   574
    a2h = sasl_md5_hex_hash (a2, strlen(a2));
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   575
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   576
    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
   577
                          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
   578
    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
   579
    g_string_append_printf (response, ",response=%s", kdh);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   580
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   581
    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
   582
    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
   583
    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
   584
    g_free (a2h);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   585
518
cdd6a0c5b439 Went 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
    /* 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
   587
    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
   588
    a2h = sasl_md5_hex_hash (a2, strlen(a2));
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   589
518
cdd6a0c5b439 Went 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
    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
   591
    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
   592
    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
   593
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   594
    g_free (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
   595
    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
   596
    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
   597
    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
   598
    g_free (kd);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   599
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   600
 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
   601
    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
   602
    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
   603
        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
   604
    } 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
   605
        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
   606
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   607
518
cdd6a0c5b439 Went 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
 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
   609
    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
   610
    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
   611
    goto out;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   612
}
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   613
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   614
static gboolean
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   615
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
   616
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   617
    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
   618
    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
   619
    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
   620
    int        result;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   621
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   622
    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
   623
    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
   624
        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
   625
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   626
518
cdd6a0c5b439 Went 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
    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
   628
                                  (gsize) strlen(response));
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
    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
   631
    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
   632
                                    "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
   633
                                    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
   634
    lm_message_node_set_value (msg->node, response64);
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
    result = lm_connection_send (sasl->connection, msg, NULL);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   637
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   638
    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
   639
    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
   640
    lm_message_unref (msg);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
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
    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
   643
        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
   644
    }
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
    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
   647
518
cdd6a0c5b439 Went 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
    return TRUE;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   649
}
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   650
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   651
static gboolean
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   652
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
   653
{
518
cdd6a0c5b439 Went 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
    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
   655
    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
   656
    int          result;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   657
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   658
    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
   659
    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
   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 (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
   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
    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
   672
        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
   673
               "%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
   674
               G_STRFUNC);
224
447f16217278 Use g_log instead of g_debug
Mikael Hallendal <micke@imendio.com>
parents: 216
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
        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
   677
            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
   678
                           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
   679
        }
cdd6a0c5b439 Went 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
        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
   681
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   682
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   683
    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
   684
    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
   685
                                    "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
   686
                                    NULL);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   687
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   688
    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
   689
    lm_message_unref (msg);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   690
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   691
    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
   692
        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
   693
        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
   694
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   695
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   696
    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
   697
518
cdd6a0c5b439 Went 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
    return TRUE;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   699
}
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   700
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   701
static gboolean
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   702
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
   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
    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
   705
    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
   706
    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
   707
    GHashTable  *h;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   708
518
cdd6a0c5b439 Went 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
    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
   710
    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
   711
        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
   712
               "%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
   713
        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
   714
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   715
518
cdd6a0c5b439 Went 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
    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
   717
    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
   718
    g_free(challenge);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   719
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   720
    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
   721
        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
   722
               "%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
   723
        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
   724
            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
   725
                           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
   726
        }
cdd6a0c5b439 Went 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
        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
   728
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   729
518
cdd6a0c5b439 Went 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
    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
   731
    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
   732
        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
   733
        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
   734
    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
   735
        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
   736
        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
   737
    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
   738
        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
   739
               "%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
   740
               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
   741
        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
   742
            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
   743
                           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
   744
        }
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   745
518
cdd6a0c5b439 Went 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
        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
   747
    } 
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   748
518
cdd6a0c5b439 Went 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
    g_hash_table_destroy(h);
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
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
    return TRUE;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   752
}
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   753
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   754
static LmHandlerResult
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   755
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
   756
                   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
   757
                   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
   758
                   gpointer          user_data)
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   759
{
518
cdd6a0c5b439 Went 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
    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
   761
    const gchar *ns;
224
447f16217278 Use g_log instead of g_debug
Mikael Hallendal <micke@imendio.com>
parents: 216
diff changeset
   762
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   763
    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
   764
    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
   765
        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
   766
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   767
518
cdd6a0c5b439 Went 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
    sasl = (LmSASL *) user_data;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   769
518
cdd6a0c5b439 Went 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
    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
   771
    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
   772
        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
   773
               "%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
   774
               G_STRFUNC);
224
447f16217278 Use g_log instead of g_debug
Mikael Hallendal <micke@imendio.com>
parents: 216
diff changeset
   775
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   776
        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
   777
            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
   778
                           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
   779
        }
cdd6a0c5b439 Went 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
        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
   781
    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
   782
        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
   783
        break;
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   784
#ifdef HAVE_GSSAPI
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   785
    case AUTH_TYPE_GSSAPI:
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   786
        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
   787
        break;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   788
#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
   789
    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
   790
        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
   791
        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
   792
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   793
518
cdd6a0c5b439 Went 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
    return LM_HANDLER_RESULT_REMOVE_MESSAGE;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   795
}
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   796
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   797
static LmHandlerResult
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   798
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
   799
                 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
   800
                 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
   801
                 gpointer          user_data)
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   802
{
518
cdd6a0c5b439 Went 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
    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
   804
    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
   805
    
cdd6a0c5b439 Went 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
    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
   807
    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
   808
        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
   809
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   810
518
cdd6a0c5b439 Went 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
    sasl = (LmSASL *) user_data;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   812
518
cdd6a0c5b439 Went 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
    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
   814
    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
   815
        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
   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;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   825
    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
   826
        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
   827
            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
   828
            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
   829
                   "%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
   830
                   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
   831
            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
   832
                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
   833
                               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
   834
            }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   835
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   836
        break;
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   837
#ifdef HAVE_GSSAPI
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   838
    case AUTH_TYPE_GSSAPI:
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   839
        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
   840
            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
   841
            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
   842
            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
   843
                   "%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
   844
                   G_STRFUNC);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   845
            if (sasl->handler) {
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   846
                sasl->handler (sasl, sasl->connection,
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   847
                               FALSE, "server error");
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   848
            }
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   849
        }
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   850
        break;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   851
#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
   852
    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
   853
        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
   854
        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
   855
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   856
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   857
    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
   858
           "%s: SASL authentication successful", G_STRFUNC);
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   859
518
cdd6a0c5b439 Went 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
    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
   861
        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
   862
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   863
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   864
    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
   865
    
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   866
}
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   867
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   868
static LmHandlerResult
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   869
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
   870
                 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
   871
                 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
   872
                 gpointer          user_data)
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   873
{
518
cdd6a0c5b439 Went 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
    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
   875
    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
   876
    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
   877
    
cdd6a0c5b439 Went 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
    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
   879
    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
   880
        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
   881
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   882
518
cdd6a0c5b439 Went 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
    sasl = (LmSASL *) user_data;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
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 (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
   886
        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
   887
        
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   888
        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
   889
        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
   890
            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
   891
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   892
    }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   893
    
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   894
    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
   895
           "%s: SASL authentication failed: %s", G_STRFUNC, reason);
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   896
518
cdd6a0c5b439 Went 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
    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
   898
        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
   899
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   900
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   901
    return LM_HANDLER_RESULT_REMOVE_MESSAGE;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   902
}
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   903
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   904
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   905
static gboolean
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   906
sasl_start (LmSASL *sasl)
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
    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
   909
    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
   910
    const char *mech = NULL;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   911
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   912
    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
   913
518
cdd6a0c5b439 Went 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
    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
   915
        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
   916
        gchar   *cstr;
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   917
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   918
        str = g_string_new ("");
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   919
518
cdd6a0c5b439 Went 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
        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
   921
        sasl->state = SASL_AUTH_STATE_PLAIN_STARTED;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   922
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
   923
        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
   924
            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
   925
                   "%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
   926
                   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
   927
            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
   928
                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
   929
            }
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
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
            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
   932
        }
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
        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
   935
        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
   936
        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
   937
        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
   938
        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
   939
                                (gsize) str->len);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   940
518
cdd6a0c5b439 Went 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
        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
   942
518
cdd6a0c5b439 Went 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
        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
   944
        g_free (cstr);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   945
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   946
        /* 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
   947
        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
   948
                                        "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
   949
                                        "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
   950
                                        NULL);
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
    } 
cdd6a0c5b439 Went 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
    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
   954
        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
   955
        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
   956
    }
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   957
#ifdef HAVE_GSSAPI
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   958
    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
   959
        mech = "GSSAPI";
564
db3e9ff448cb Style fixes for GSSAPI changes [#20].
Mikael Hallendal <micke@imendio.com>
parents: 563
diff changeset
   960
        sasl_gssapi_start (sasl, auth_msg->node);
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   961
    }
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   962
#endif
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
    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
   965
                                    "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
   966
                                    "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
   967
                                    NULL);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   968
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   969
    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
   970
    lm_message_unref (auth_msg);
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   971
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   972
    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
   973
        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
   974
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   975
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   976
    return TRUE;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   977
}
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   978
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   979
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
   980
sasl_set_auth_type (LmSASL *sasl, LmMessageNode *mechanisms)
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   981
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   982
    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
   983
    const gchar   *ns;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
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
    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
   986
518
cdd6a0c5b439 Went 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
    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
   988
    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
   989
        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
   990
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
   991
518
cdd6a0c5b439 Went 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
    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
   993
        const gchar *name;
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
   994
518
cdd6a0c5b439 Went 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
        name = lm_message_node_get_value (m);
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
   996
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
   997
        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
   998
            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
   999
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1000
        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
  1001
            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
  1002
            continue;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1003
        }
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1004
        if (strcmp (name, "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
  1005
            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
  1006
            continue;
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1007
        }
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
  1008
        if (strcmp (name, "GSSAPI") == 0) {
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
  1009
            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
  1010
            continue;
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
  1011
        }
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
  1012
        
518
cdd6a0c5b439 Went 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
        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
  1014
               "%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
  1015
    }
255
704881ac7788 Fixed potential problem if auth was not called from the open callback.
Mikael Hallendal <micke@imendio.com>
parents: 227
diff changeset
  1016
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1017
    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
  1018
}
704881ac7788 Fixed potential problem if auth was not called from the open callback.
Mikael Hallendal <micke@imendio.com>
parents: 227
diff changeset
  1019
704881ac7788 Fixed potential problem if auth was not called from the open callback.
Mikael Hallendal <micke@imendio.com>
parents: 227
diff changeset
  1020
static gboolean
704881ac7788 Fixed potential problem if auth was not called from the open callback.
Mikael Hallendal <micke@imendio.com>
parents: 227
diff changeset
  1021
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
  1022
{
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1023
    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
  1024
        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
  1025
               "%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
  1026
               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
  1027
518
cdd6a0c5b439 Went 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
        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
  1029
    }
255
704881ac7788 Fixed potential problem if auth was not called from the open callback.
Mikael Hallendal <micke@imendio.com>
parents: 227
diff changeset
  1030
563
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
  1031
    /* Prefer GSSAPI if available */
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
  1032
#ifdef HAVE_GSSAPI
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
  1033
    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
  1034
        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
  1035
        return sasl_start (sasl);
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
  1036
    }
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
  1037
#endif
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
  1038
    /* Otherwise prefer DIGEST */
33ffbface103 Applied patch to add GSSAPI support to Loudmouth [#20]
Jelmer Vernooij <jelmer@samba.org>
parents: 540
diff changeset
  1039
    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
  1040
        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
  1041
        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
  1042
    }
cdd6a0c5b439 Went 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
    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
  1044
        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
  1045
        return sasl_start (sasl);
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1046
    } 
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
    return FALSE;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1049
}
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1050
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1051
static LmHandlerResult
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
  1052
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
  1053
                  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
  1054
                  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
  1055
                  gpointer          user_data)
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
    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
  1058
    LmSASL        *sasl;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1059
518
cdd6a0c5b439 Went 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
    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
  1061
    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
  1062
    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
  1063
        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
  1064
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1065
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1066
    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
  1067
    sasl->features_received = TRUE;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
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
    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
  1070
518
cdd6a0c5b439 Went 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
    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
  1072
        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
  1073
    }
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1074
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1075
    return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1076
}
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1077
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
  1078
LmSASL *
255
704881ac7788 Fixed potential problem if auth was not called from the open callback.
Mikael Hallendal <micke@imendio.com>
parents: 227
diff changeset
  1079
lm_sasl_new (LmConnection *connection)
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
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
    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
  1082
    
cdd6a0c5b439 Went 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
    sasl = g_new0 (LmSASL, 1);
216
fab18da0956b Added lm-sasl.[ch] from Senko
Mikael Hallendal <micke@imendio.com>
parents:
diff changeset
  1084
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1085
    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
  1086
    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
  1087
    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
  1088
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1089
    sasl->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
  1090
                                                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
  1091
                                                NULL);
255
704881ac7788 Fixed potential problem if auth was not called from the open callback.
Mikael Hallendal <micke@imendio.com>
parents: 227
diff changeset
  1092
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1093
    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
  1094
                                            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
  1095
                                            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
  1096
                                            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
  1097
    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
  1098
}
704881ac7788 Fixed potential problem if auth was not called from the open callback.
Mikael Hallendal <micke@imendio.com>
parents: 227
diff changeset
  1099
704881ac7788 Fixed potential problem if auth was not called from the open callback.
Mikael Hallendal <micke@imendio.com>
parents: 227
diff changeset
  1100
void
704881ac7788 Fixed potential problem if auth was not called from the open callback.
Mikael Hallendal <micke@imendio.com>
parents: 227
diff changeset
  1101
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
  1102
                      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
  1103
                      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
  1104
                      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
  1105
{
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
  1106
    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
  1107
    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
  1108
    sasl->handler     = handler;
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
  1109
518
cdd6a0c5b439 Went 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->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
  1111
                                                 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
  1112
                                                 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
  1113
    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
  1114
                                            sasl->challenge_cb,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1115
                                            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
  1116
                                            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
  1117
    
cdd6a0c5b439 Went 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->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
  1119
                                               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
  1120
                                               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
  1121
    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
  1122
                                            sasl->success_cb,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1123
                                            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
  1124
                                            LM_HANDLER_PRIORITY_FIRST);
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
  1125
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1126
    sasl->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
  1127
                                               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
  1128
                                               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
  1129
    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
  1130
                                            sasl->failure_cb,
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1131
                                            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
  1132
                                            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
  1133
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1134
    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
  1135
        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
  1136
    } 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
  1137
        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
  1138
    }
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
  1139
}
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
  1140
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
  1141
void
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
  1142
lm_sasl_free (LmSASL *sasl)
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
  1143
{
518
cdd6a0c5b439 Went 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
    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
  1145
    
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
  1146
    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
  1147
        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
  1148
    }
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
  1149
518
cdd6a0c5b439 Went 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
    g_free (sasl->server);
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->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
  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->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
  1155
                                                  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
  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->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
  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->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
  1161
                                                  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
  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
    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
  1165
        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
  1166
                                                  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
  1167
                                                  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
  1168
    }
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
  1169
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1170
    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
  1171
        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
  1172
                                                  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
  1173
                                                  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
  1174
    }
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
  1175
518
cdd6a0c5b439 Went over all of the files and made sure they all were indented the same way.
Mikael Hallendal <micke@imendio.com>
parents: 516
diff changeset
  1176
    g_free (sasl);
227
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
  1177
}
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
  1178
b8fa5635fb30 Conform with Loudmouth coding style
Mikael Hallendal <micke@imendio.com>
parents: 225
diff changeset
  1179
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
  1180
LmAuthParameters *
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
  1181
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
  1182
{
540
72acfccdec86 Switch to use LmAuthParameters instead of passing around username and password.
Mikael Hallendal <micke@imendio.com>
parents: 518
diff changeset
  1183
    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
  1184
}
6b6ad42cd508 Support obsolete XEP-0078 (old-style jabber auth for XMPP1.0).
Senko Rasic <senko@phyrexia.lan>
parents: 321
diff changeset
  1185