xref: /titanic_41/usr/src/cmd/ssh/sshd/auth2-passwd.c (revision 1816cb7076d3ec8a78ef9ac9f895574e13c43645)
1 /*
2  * Copyright (c) 2000 Markus Friedl.  All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  */
24 /*
25  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
26  * Use is subject to license terms.
27  */
28 
29 #include "includes.h"
30 RCSID("$OpenBSD: auth2-passwd.c,v 1.2 2002/05/31 11:35:15 markus Exp $");
31 
32 #pragma ident	"%Z%%M%	%I%	%E% SMI"
33 
34 #include "xmalloc.h"
35 #include "packet.h"
36 #include "log.h"
37 #include "auth.h"
38 #include "servconf.h"
39 
40 /* import */
41 extern ServerOptions options;
42 
43 static void
44 userauth_passwd(Authctxt *authctxt)
45 {
46 	char *password;
47 	int change;
48 	u_int len;
49 
50 	if (!authctxt || !authctxt->method)
51 		fatal("%s: missing context", __func__);
52 
53 	change = packet_get_char();
54 	if (change)
55 		log("password change not supported");
56 	password = packet_get_string(&len);
57 	packet_check_eom();
58 	if (
59 #ifdef HAVE_CYGWIN
60 	    check_nt_auth(1, authctxt->pw) &&
61 #endif
62 	    auth_password(authctxt, password) == 1) {
63 		authctxt->method->authenticated = 1;
64 	}
65 	memset(password, 0, len);
66 	xfree(password);
67 }
68 
69 Authmethod method_passwd = {
70 	"password",
71 	&options.password_authentication,
72 	userauth_passwd,
73 	NULL,		    /* no abandon function */
74 	NULL, NULL,	    /* method data and hist data */
75 	1,		    /* initial userauth */
76 	0, 0, 0,	    /* counters */
77 	0, 0, 0, 0, 0, 0    /* state */
78 };
79