xref: /titanic_50/usr/src/cmd/ssh/sshd/auth2-passwd.c (revision 9a8058b57457911fab0e3b4b6f0a97740e7a816d)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * Copyright (c) 2000 Markus Friedl.  All rights reserved.
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * Redistribution and use in source and binary forms, with or without
57c478bd9Sstevel@tonic-gate  * modification, are permitted provided that the following conditions
67c478bd9Sstevel@tonic-gate  * are met:
77c478bd9Sstevel@tonic-gate  * 1. Redistributions of source code must retain the above copyright
87c478bd9Sstevel@tonic-gate  *    notice, this list of conditions and the following disclaimer.
97c478bd9Sstevel@tonic-gate  * 2. Redistributions in binary form must reproduce the above copyright
107c478bd9Sstevel@tonic-gate  *    notice, this list of conditions and the following disclaimer in the
117c478bd9Sstevel@tonic-gate  *    documentation and/or other materials provided with the distribution.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
147c478bd9Sstevel@tonic-gate  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
157c478bd9Sstevel@tonic-gate  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
167c478bd9Sstevel@tonic-gate  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
177c478bd9Sstevel@tonic-gate  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
187c478bd9Sstevel@tonic-gate  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
197c478bd9Sstevel@tonic-gate  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
207c478bd9Sstevel@tonic-gate  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
217c478bd9Sstevel@tonic-gate  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
227c478bd9Sstevel@tonic-gate  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
237c478bd9Sstevel@tonic-gate  */
247c478bd9Sstevel@tonic-gate /*
25*9a8058b5Sjp161948  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
267c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
277c478bd9Sstevel@tonic-gate  */
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #include "includes.h"
307c478bd9Sstevel@tonic-gate RCSID("$OpenBSD: auth2-passwd.c,v 1.2 2002/05/31 11:35:15 markus Exp $");
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #include "xmalloc.h"
357c478bd9Sstevel@tonic-gate #include "packet.h"
367c478bd9Sstevel@tonic-gate #include "log.h"
377c478bd9Sstevel@tonic-gate #include "auth.h"
387c478bd9Sstevel@tonic-gate #include "servconf.h"
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate /* import */
417c478bd9Sstevel@tonic-gate extern ServerOptions options;
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate static void
userauth_passwd(Authctxt * authctxt)447c478bd9Sstevel@tonic-gate userauth_passwd(Authctxt *authctxt)
457c478bd9Sstevel@tonic-gate {
467c478bd9Sstevel@tonic-gate 	char *password;
477c478bd9Sstevel@tonic-gate 	int change;
487c478bd9Sstevel@tonic-gate 	u_int len;
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate 	if (!authctxt || !authctxt->method)
517c478bd9Sstevel@tonic-gate 		fatal("%s: missing context", __func__);
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate 	change = packet_get_char();
547c478bd9Sstevel@tonic-gate 	if (change)
557c478bd9Sstevel@tonic-gate 		log("password change not supported");
567c478bd9Sstevel@tonic-gate 	password = packet_get_string(&len);
577c478bd9Sstevel@tonic-gate 	packet_check_eom();
587c478bd9Sstevel@tonic-gate 	if (
597c478bd9Sstevel@tonic-gate #ifdef HAVE_CYGWIN
607c478bd9Sstevel@tonic-gate 	    check_nt_auth(1, authctxt->pw) &&
617c478bd9Sstevel@tonic-gate #endif
62*9a8058b5Sjp161948 	    auth_password(authctxt, password) == 1) {
637c478bd9Sstevel@tonic-gate 		authctxt->method->authenticated = 1;
64*9a8058b5Sjp161948 	}
657c478bd9Sstevel@tonic-gate 	memset(password, 0, len);
667c478bd9Sstevel@tonic-gate 	xfree(password);
677c478bd9Sstevel@tonic-gate }
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate Authmethod method_passwd = {
707c478bd9Sstevel@tonic-gate 	"password",
717c478bd9Sstevel@tonic-gate 	&options.password_authentication,
727c478bd9Sstevel@tonic-gate 	userauth_passwd,
737c478bd9Sstevel@tonic-gate 	NULL,		    /* no abandon function */
747c478bd9Sstevel@tonic-gate 	NULL, NULL,	    /* method data and hist data */
757c478bd9Sstevel@tonic-gate 	1,		    /* initial userauth */
767c478bd9Sstevel@tonic-gate 	0, 0, 0,	    /* counters */
777c478bd9Sstevel@tonic-gate 	0, 0, 0, 0, 0, 0    /* state */
787c478bd9Sstevel@tonic-gate };
79