[650ac700] | 1 | /* |
---|
| 2 | * Authorship |
---|
| 3 | * ---------- |
---|
| 4 | * This software was created by |
---|
| 5 | * Till Straumann <strauman@slac.stanford.edu>, 2003-2007 |
---|
| 6 | * Stanford Linear Accelerator Center, Stanford University. |
---|
| 7 | * |
---|
| 8 | * Acknowledgement of sponsorship |
---|
| 9 | * ------------------------------ |
---|
| 10 | * This software was produced by |
---|
| 11 | * the Stanford Linear Accelerator Center, Stanford University, |
---|
| 12 | * under Contract DE-AC03-76SFO0515 with the Department of Energy. |
---|
| 13 | * |
---|
| 14 | * Government disclaimer of liability |
---|
| 15 | * ---------------------------------- |
---|
| 16 | * Neither the United States nor the United States Department of Energy, |
---|
| 17 | * nor any of their employees, makes any warranty, express or implied, or |
---|
| 18 | * assumes any legal liability or responsibility for the accuracy, |
---|
| 19 | * completeness, or usefulness of any data, apparatus, product, or process |
---|
| 20 | * disclosed, or represents that its use would not infringe privately owned |
---|
| 21 | * rights. |
---|
| 22 | * |
---|
| 23 | * Stanford disclaimer of liability |
---|
| 24 | * -------------------------------- |
---|
| 25 | * Stanford University makes no representations or warranties, express or |
---|
| 26 | * implied, nor assumes any liability for the use of this software. |
---|
| 27 | * |
---|
| 28 | * Stanford disclaimer of copyright |
---|
| 29 | * -------------------------------- |
---|
| 30 | * Stanford University, owner of the copyright, hereby disclaims its |
---|
| 31 | * copyright and all other rights in this software. Hence, anyone may |
---|
| 32 | * freely use it for any purpose without restriction. |
---|
| 33 | * |
---|
| 34 | * Maintenance of notices |
---|
| 35 | * ---------------------- |
---|
| 36 | * In the interest of clarity regarding the origin and status of this |
---|
| 37 | * SLAC software, this and all the preceding Stanford University notices |
---|
| 38 | * are to remain affixed to any copy or derivative of this software made |
---|
| 39 | * or distributed by the recipient and are to be affixed to any copy of |
---|
| 40 | * software made or distributed by the recipient that contains a copy or |
---|
| 41 | * derivative of this software. |
---|
| 42 | * |
---|
| 43 | * ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03 |
---|
| 44 | * |
---|
[bcef89f2] | 45 | * Copyright (c) 2009 embedded brains GmbH & Co. KG |
---|
[650ac700] | 46 | * |
---|
| 47 | * The license and distribution terms for this file may be |
---|
| 48 | * found in the file LICENSE in this distribution or at |
---|
| 49 | * http://www.rtems.org/license/LICENSE. |
---|
| 50 | */ |
---|
| 51 | |
---|
| 52 | #ifdef HAVE_CONFIG_H |
---|
| 53 | #include "config.h" |
---|
| 54 | #endif |
---|
| 55 | |
---|
| 56 | #include <termios.h> |
---|
| 57 | #include <errno.h> |
---|
| 58 | #include <stdio.h> |
---|
| 59 | #include <unistd.h> |
---|
| 60 | #include <stdlib.h> |
---|
| 61 | #include <string.h> |
---|
| 62 | #include <syslog.h> |
---|
| 63 | |
---|
| 64 | #include <rtems/telnetd.h> |
---|
| 65 | |
---|
| 66 | #include "des.h" |
---|
| 67 | #include <rtems/passwd.h> |
---|
| 68 | |
---|
| 69 | /** |
---|
| 70 | * @brief Standard Telnet login check that uses DES to encrypt the passphrase. |
---|
| 71 | * |
---|
| 72 | * Takes a @a passphrase, encrypts it and compares it to the encrypted |
---|
| 73 | * passphrase in the @c TELNETD_PASSWD environment variable. No password is |
---|
| 74 | * required if @c TELNETD_PASSWD is unset. The argument @a user is ignored. |
---|
| 75 | */ |
---|
| 76 | bool rtems_telnetd_login_check( |
---|
| 77 | const char *user, |
---|
| 78 | const char *passphrase |
---|
| 79 | ) |
---|
| 80 | { |
---|
| 81 | char *pw = getenv( "TELNETD_PASSWD"); |
---|
| 82 | char cryptbuf [21]; |
---|
| 83 | char salt [3]; |
---|
| 84 | |
---|
| 85 | if (pw == NULL || strlen( pw) == 0) { |
---|
| 86 | #ifdef TELNETD_DEFAULT_PASSWD |
---|
| 87 | pw = TELNETD_DEFAULT_PASSWD; |
---|
| 88 | #else |
---|
| 89 | return true; |
---|
| 90 | #endif |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | strncpy( salt, pw, 2); |
---|
| 94 | salt [2] = '\0'; |
---|
| 95 | |
---|
| 96 | return strcmp( |
---|
| 97 | __des_crypt_r( passphrase, salt, cryptbuf, sizeof( cryptbuf)), |
---|
| 98 | pw |
---|
| 99 | ) == 0; |
---|
| 100 | } |
---|