source: rtems/cpukit/libmisc/shell/login_check.c

Last change on this file was bcef89f2, checked in by Sebastian Huber <sebastian.huber@…>, on 05/19/23 at 06:18:25

Update company name

The embedded brains GmbH & Co. KG is the legal successor of embedded
brains GmbH.

  • Property mode set to 100644
File size: 1.6 KB
Line 
1/**
2 * @file
3 *
4 * @brief Shell login check function.
5 */
6
7/*
8 * Copyright (C) 2009, 2014 embedded brains GmbH & Co. KG
9 *
10 * Based on work from Chris Johns and Fernando Ruiz.
11 *
12 * Derived from file "cpukit/libmisc/shell/shell.c".
13 *
14 * The license and distribution terms for this file may be
15 * found in the file LICENSE in this distribution or at
16 * http://www.rtems.org/license/LICENSE.
17 */
18
19#ifdef HAVE_CONFIG_H
20#include "config.h"
21#endif
22
23#include <sys/types.h>
24#include <unistd.h>
25#include <pwd.h>
26#include <string.h>
27#include <crypt.h>
28
29#include <rtems/shell.h>
30#include <rtems/userenv.h>
31
32bool rtems_shell_login_check(
33  const char *user,
34  const char *passphrase
35)
36{
37  char buf[256];
38  struct passwd *pw_res;
39  struct passwd pw;
40  int eno;
41  bool ok;
42
43  eno = getpwnam_r(user, &pw, &buf[0], sizeof(buf), &pw_res);
44
45  /* Valid user? */
46  if (eno == 0 && strcmp(pw.pw_passwd, "*") != 0) {
47    if (strcmp(pw.pw_passwd, "") == 0) {
48      ok = true;
49    } else if (strcmp(pw.pw_passwd, "x") == 0) {
50      /* TODO: /etc/shadow */
51      ok = false;
52    } else {
53      struct crypt_data data;
54      char *s;
55
56      s = crypt_r(passphrase, pw.pw_passwd, &data);
57      ok = strcmp(s, pw.pw_passwd) == 0;
58    }
59  } else {
60    ok = false;
61  }
62
63  if (ok && strcmp(pw.pw_dir, "") != 0) {
64    ok = chroot(pw.pw_dir) == 0;
65  }
66
67  if (ok) {
68    rtems_shell_env_t *env = rtems_shell_get_current_env();
69
70    if (env != NULL) {
71      chown(env->devname, pw.pw_uid, 0);
72    }
73
74    setuid(pw.pw_uid);
75    setgid(pw.pw_gid);
76    seteuid(pw.pw_uid);
77    setegid(pw.pw_gid);
78    rtems_current_user_env_getgroups();
79  }
80
81  return ok;
82}
Note: See TracBrowser for help on using the repository browser.