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 | * |
---|
45 | * Copyright (c) 2009 embedded brains GmbH and others. |
---|
46 | * |
---|
47 | * embedded brains GmbH |
---|
48 | * Obere Lagerstr. 30 |
---|
49 | * D-82178 Puchheim |
---|
50 | * Germany |
---|
51 | * <rtems@embedded-brains.de> |
---|
52 | * |
---|
53 | * The license and distribution terms for this file may be |
---|
54 | * found in the file LICENSE in this distribution or at |
---|
55 | * http://www.rtems.org/license/LICENSE. |
---|
56 | */ |
---|
57 | |
---|
58 | #ifdef HAVE_CONFIG_H |
---|
59 | #include "config.h" |
---|
60 | #endif |
---|
61 | |
---|
62 | #include <termios.h> |
---|
63 | #include <errno.h> |
---|
64 | #include <stdio.h> |
---|
65 | #include <unistd.h> |
---|
66 | #include <stdlib.h> |
---|
67 | #include <string.h> |
---|
68 | #include <syslog.h> |
---|
69 | |
---|
70 | #include <rtems/telnetd.h> |
---|
71 | |
---|
72 | #include "des.h" |
---|
73 | #include "passwd.h" |
---|
74 | |
---|
75 | /** |
---|
76 | * @brief Standard Telnet login check that uses DES to encrypt the passphrase. |
---|
77 | * |
---|
78 | * Takes a @a passphrase, encrypts it and compares it to the encrypted |
---|
79 | * passphrase in the @c TELNETD_PASSWD environment variable. No password is |
---|
80 | * required if @c TELNETD_PASSWD is unset. The argument @a user is ignored. |
---|
81 | */ |
---|
82 | bool rtems_telnetd_login_check( |
---|
83 | const char *user, |
---|
84 | const char *passphrase |
---|
85 | ) |
---|
86 | { |
---|
87 | char *pw = getenv( "TELNETD_PASSWD"); |
---|
88 | char cryptbuf [21]; |
---|
89 | char salt [3]; |
---|
90 | |
---|
91 | if (pw == NULL || strlen( pw) == 0) { |
---|
92 | #ifdef TELNETD_DEFAULT_PASSWD |
---|
93 | pw = TELNETD_DEFAULT_PASSWD; |
---|
94 | #else |
---|
95 | return true; |
---|
96 | #endif |
---|
97 | } |
---|
98 | |
---|
99 | strncpy( salt, pw, 2); |
---|
100 | salt [2] = '\0'; |
---|
101 | |
---|
102 | return strcmp( |
---|
103 | __des_crypt_r( passphrase, salt, cryptbuf, sizeof( cryptbuf)), |
---|
104 | pw |
---|
105 | ) == 0; |
---|
106 | } |
---|