1*19c14409Schristos /* $NetBSD: mech_login.c,v 1.3 2011/02/11 23:44:43 christos Exp $ */
2231558cbSagc
3231558cbSagc /* Copyright (c) 2010 The NetBSD Foundation, Inc.
4231558cbSagc * All rights reserved.
5231558cbSagc *
6231558cbSagc * This code is derived from software contributed to The NetBSD Foundation
7231558cbSagc * by Mateusz Kocielski.
8231558cbSagc *
9231558cbSagc * Redistribution and use in source and binary forms, with or without
10231558cbSagc * modification, are permitted provided that the following conditions
11231558cbSagc * are met:
12231558cbSagc * 1. Redistributions of source code must retain the above copyright
13231558cbSagc * notice, this list of conditions and the following disclaimer.
14231558cbSagc * 2. Redistributions in binary form must reproduce the above copyright
15231558cbSagc * notice, this list of conditions and the following disclaimer in the
16231558cbSagc * documentation and/or other materials provided with the distribution.
17231558cbSagc * 3. All advertising materials mentioning features or use of this software
18231558cbSagc * must display the following acknowledgement:
19231558cbSagc * This product includes software developed by the NetBSD
20231558cbSagc * Foundation, Inc. and its contributors.
21231558cbSagc * 4. Neither the name of The NetBSD Foundation nor the names of its
22231558cbSagc * contributors may be used to endorse or promote products derived
23231558cbSagc * from this software without specific prior written permission.
24231558cbSagc *
25231558cbSagc * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
26231558cbSagc * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27231558cbSagc * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28231558cbSagc * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
29231558cbSagc * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30231558cbSagc * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31231558cbSagc * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32231558cbSagc * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33231558cbSagc * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34231558cbSagc * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35231558cbSagc * POSSIBILITY OF SUCH DAMAGE.
36231558cbSagc */
37*19c14409Schristos #include <sys/cdefs.h>
38*19c14409Schristos __RCSID("$NetBSD: mech_login.c,v 1.3 2011/02/11 23:44:43 christos Exp $");
39231558cbSagc
40*19c14409Schristos #include <assert.h>
41231558cbSagc #include <saslc.h>
42231558cbSagc #include <stdio.h>
43231558cbSagc #include <string.h>
44231558cbSagc
45*19c14409Schristos #include "mech.h"
46*19c14409Schristos #include "saslc_private.h"
47*19c14409Schristos
48*19c14409Schristos
49*19c14409Schristos /* Non-standard: no RFC. */
50231558cbSagc
51231558cbSagc /* properties */
52*19c14409Schristos #define SASLC_LOGIN_AUTHCID SASLC_PROP_AUTHCID
53*19c14409Schristos #define SASLC_LOGIN_PASSWD SASLC_PROP_PASSWD
54231558cbSagc
55231558cbSagc /**
56231558cbSagc * @brief doing one step of the sasl authentication
57231558cbSagc * @param sess sasl session
58231558cbSagc * @param in input data
59231558cbSagc * @param inlen input data length
60231558cbSagc * @param out place to store output data
61231558cbSagc * @param outlen output data length
62231558cbSagc * @return MECH_OK - success,
63231558cbSagc * MECH_STEP - more steps are needed,
64231558cbSagc * MECH_ERROR - error
65231558cbSagc */
66231558cbSagc /*ARGSUSED*/
67231558cbSagc static int
saslc__mech_login_cont(saslc_sess_t * sess,const void * in __unused,size_t inlen __unused,void ** out,size_t * outlen)68*19c14409Schristos saslc__mech_login_cont(saslc_sess_t *sess, const void *in __unused,
69*19c14409Schristos size_t inlen __unused, void **out, size_t *outlen)
70231558cbSagc {
71231558cbSagc saslc__mech_sess_t *ms = sess->mech_sess;
72*19c14409Schristos
73231558cbSagc switch (ms->step) {
74231558cbSagc case 0:
75231558cbSagc if (saslc__mech_strdup(sess, (char **)out, outlen,
76*19c14409Schristos SASLC_LOGIN_AUTHCID,
77*19c14409Schristos "authcid is required for an authentication") == MECH_OK)
78231558cbSagc return MECH_STEP;
79231558cbSagc else
80231558cbSagc return MECH_ERROR;
81231558cbSagc case 1:
82231558cbSagc return saslc__mech_strdup(sess, (char **)out, outlen,
83*19c14409Schristos SASLC_LOGIN_PASSWD,
84231558cbSagc "passwd is required for an authentication");
85231558cbSagc default:
86231558cbSagc assert(/*CONSTCOND*/0); /* impossible */
87231558cbSagc return MECH_ERROR;
88231558cbSagc }
89231558cbSagc }
90231558cbSagc
91231558cbSagc /* mechanism definition */
92231558cbSagc const saslc__mech_t saslc__mech_login = {
93*19c14409Schristos .name = "LOGIN",
94*19c14409Schristos .flags = FLAG_PLAINTEXT,
95*19c14409Schristos .create = saslc__mech_generic_create,
96*19c14409Schristos .cont = saslc__mech_login_cont,
97*19c14409Schristos .encode = NULL,
98*19c14409Schristos .decode = NULL,
99*19c14409Schristos .destroy = saslc__mech_generic_destroy
100231558cbSagc };
101