xref: /titanic_50/usr/src/cmd/ssh/sshd/auth2-passwd.c (revision ba2e4443695ee6a6f420a35cd4fc3d3346d22932)
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 2004 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 "monitor_wrap.h"
39 #include "servconf.h"
40 
41 /* import */
42 extern ServerOptions options;
43 
44 static void
45 userauth_passwd(Authctxt *authctxt)
46 {
47 	char *password;
48 	int change;
49 	u_int len;
50 
51 	if (!authctxt || !authctxt->method)
52 		fatal("%s: missing context", __func__);
53 
54 	change = packet_get_char();
55 	if (change)
56 		log("password change not supported");
57 	password = packet_get_string(&len);
58 	packet_check_eom();
59 	if (
60 #ifdef HAVE_CYGWIN
61 	    check_nt_auth(1, authctxt->pw) &&
62 #endif
63 	    PRIVSEP(auth_password(authctxt, password)) == 1)
64 		authctxt->method->authenticated = 1;
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