1 /* $NetBSD: auth2-passwd.c,v 1.13 2020/05/28 17:05:49 christos Exp $ */ 2 /* $OpenBSD: auth2-passwd.c,v 1.18 2020/02/26 13:40:09 jsg Exp $ */ 3 /* 4 * Copyright (c) 2000 Markus Friedl. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27 #include "includes.h" 28 __RCSID("$NetBSD: auth2-passwd.c,v 1.13 2020/05/28 17:05:49 christos Exp $"); 29 #include <sys/types.h> 30 31 #include <stdlib.h> 32 #include <string.h> 33 #include <stdarg.h> 34 #include <stdio.h> 35 36 #include "packet.h" 37 #include "ssherr.h" 38 #include "log.h" 39 #include "sshkey.h" 40 #include "hostfile.h" 41 #include "auth.h" 42 #ifdef GSSAPI 43 #include "ssh-gss.h" 44 #endif 45 #include "monitor_wrap.h" 46 #include "misc.h" 47 #include "servconf.h" 48 49 /* import */ 50 extern ServerOptions options; 51 52 static int 53 userauth_passwd(struct ssh *ssh) 54 { 55 char *password; 56 int authenticated = 0, r; 57 u_char change; 58 size_t len; 59 60 if ((r = sshpkt_get_u8(ssh, &change)) != 0 || 61 (r = sshpkt_get_cstring(ssh, &password, &len)) != 0 || 62 (change && (r = sshpkt_get_cstring(ssh, NULL, NULL)) != 0) || 63 (r = sshpkt_get_end(ssh)) != 0) 64 fatal("%s: %s", __func__, ssh_err(r)); 65 66 if (change) 67 logit("password change not supported"); 68 else if (PRIVSEP(auth_password(ssh, password)) == 1) 69 authenticated = 1; 70 freezero(password, len); 71 return authenticated; 72 } 73 74 Authmethod method_passwd = { 75 "password", 76 userauth_passwd, 77 &options.password_authentication 78 }; 79