source: rtems/cpukit/telnetd/check_passwd.c @ c499856

4.11
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on Mar 20, 2014 at 9:10:47 PM

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 3.2 KB
Line 
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 "passwd.h"
73
74char *__des_crypt_r( const char *, const char *, char *, int);
75
76/**
77 * @brief Standard Telnet login check that uses DES to encrypt the passphrase.
78 *
79 * Takes a @a passphrase, encrypts it and compares it to the encrypted
80 * passphrase in the @c TELNETD_PASSWD environment variable.  No password is
81 * required if @c TELNETD_PASSWD is unset.  The argument @a user is ignored.
82 */
83bool rtems_telnetd_login_check(
84  const char *user,
85  const char *passphrase
86)
87{
88  char *pw = getenv( "TELNETD_PASSWD");
89  char cryptbuf [21];
90  char salt [3];
91
92  if (pw == NULL || strlen( pw) == 0) {
93    #ifdef TELNETD_DEFAULT_PASSWD
94      pw = TELNETD_DEFAULT_PASSWD;
95    #else
96      return true;
97    #endif
98  }
99
100  strncpy( salt, pw, 2);
101  salt [2] = '\0';
102
103  return strcmp(
104    __des_crypt_r( passphrase, salt, cryptbuf, sizeof( cryptbuf)),
105    pw
106  ) == 0;
107}
Note: See TracBrowser for help on using the repository browser.