[BACK]Return to auth2-none.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / ssh

Annotation of src/usr.bin/ssh/auth2-none.c, Revision 1.12

1.12    ! deraadt     1: /* $OpenBSD: auth2-none.c,v 1.11 2006/07/09 15:15:10 stevesk Exp $ */
1.1       markus      2: /*
                      3:  * Copyright (c) 2000 Markus Friedl.  All rights reserved.
                      4:  *
                      5:  * Redistribution and use in source and binary forms, with or without
                      6:  * modification, are permitted provided that the following conditions
                      7:  * are met:
                      8:  * 1. Redistributions of source code must retain the above copyright
                      9:  *    notice, this list of conditions and the following disclaimer.
                     10:  * 2. Redistributions in binary form must reproduce the above copyright
                     11:  *    notice, this list of conditions and the following disclaimer in the
                     12:  *    documentation and/or other materials provided with the distribution.
                     13:  *
                     14:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
                     15:  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
                     16:  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
                     17:  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
                     18:  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
                     19:  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
                     20:  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
                     21:  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
                     22:  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
                     23:  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
                     24:  */
                     25:
1.8       stevesk    26: #include <sys/types.h>
                     27: #include <sys/stat.h>
1.11      stevesk    28:
                     29: #include <fcntl.h>
1.1       markus     30:
1.12    ! deraadt    31: #include "xmalloc.h"
        !            32: #include "key.h"
        !            33: #include "hostfile.h"
1.1       markus     34: #include "auth.h"
                     35: #include "packet.h"
                     36: #include "log.h"
1.12    ! deraadt    37: #include "buffer.h"
1.1       markus     38: #include "servconf.h"
                     39: #include "atomicio.h"
                     40: #include "compat.h"
                     41: #include "ssh2.h"
1.12    ! deraadt    42: #ifdef GSSAPI
        !            43: #include "ssh-gss.h"
        !            44: #endif
1.1       markus     45: #include "monitor_wrap.h"
                     46:
                     47: /* import */
                     48: extern ServerOptions options;
                     49:
1.2       markus     50: /* "none" is allowed only one time */
                     51: static int none_enabled = 1;
                     52:
1.1       markus     53: char *
                     54: auth2_read_banner(void)
                     55: {
                     56:        struct stat st;
                     57:        char *banner = NULL;
1.7       deraadt    58:        size_t len, n;
1.1       markus     59:        int fd;
                     60:
                     61:        if ((fd = open(options.banner, O_RDONLY)) == -1)
                     62:                return (NULL);
                     63:        if (fstat(fd, &st) == -1) {
                     64:                close(fd);
                     65:                return (NULL);
                     66:        }
1.7       deraadt    67:        if (st.st_size > 1*1024*1024) {
                     68:                close(fd);
                     69:                return (NULL);
                     70:        }
                     71:
                     72:        len = (size_t)st.st_size;               /* truncate */
1.1       markus     73:        banner = xmalloc(len + 1);
                     74:        n = atomicio(read, fd, banner, len);
                     75:        close(fd);
                     76:
                     77:        if (n != len) {
1.4       deraadt    78:                xfree(banner);
1.1       markus     79:                return (NULL);
                     80:        }
                     81:        banner[n] = '\0';
1.3       deraadt    82:
1.1       markus     83:        return (banner);
                     84: }
                     85:
                     86: static void
                     87: userauth_banner(void)
                     88: {
                     89:        char *banner = NULL;
                     90:
                     91:        if (options.banner == NULL || (datafellows & SSH_BUG_BANNER))
                     92:                return;
                     93:
                     94:        if ((banner = PRIVSEP(auth2_read_banner())) == NULL)
                     95:                goto done;
                     96:
                     97:        packet_start(SSH2_MSG_USERAUTH_BANNER);
                     98:        packet_put_cstring(banner);
                     99:        packet_put_cstring("");         /* language, unused */
                    100:        packet_send();
                    101:        debug("userauth_banner: sent");
                    102: done:
                    103:        if (banner)
                    104:                xfree(banner);
                    105: }
                    106:
1.2       markus    107: static int
1.1       markus    108: userauth_none(Authctxt *authctxt)
                    109: {
1.2       markus    110:        none_enabled = 0;
1.1       markus    111:        packet_check_eom();
                    112:        userauth_banner();
1.6       markus    113:        if (options.password_authentication)
1.5       markus    114:                return (PRIVSEP(auth_password(authctxt, "")));
                    115:        return (0);
1.1       markus    116: }
1.2       markus    117:
                    118: Authmethod method_none = {
                    119:        "none",
                    120:        userauth_none,
                    121:        &none_enabled
                    122: };