annotate toys/other/login.c @ 877:37e668afd008

Isaac Dunham pointed out that the kernel treats - and _ as identical in module names, so modinfo should too. Made it use mmap() while I was there, and some cosmetic refactoring.
author Rob Landley <rob@landley.net>
date Wed, 24 Apr 2013 03:04:31 -0500
parents 0ed3351d91eb
children faf7117c4489
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
1 /* login.c - Start a session on the system.
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
2 *
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
3 * Copyright 2012 Elie De Brauwer <eliedebrauwer@gmail.com>
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
4 *
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
5 * No support for PAM/securetty/selinux/login script/issue/utmp
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
6 * Relies on libcrypt for hash calculation.
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
7
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
8 USE_LOGIN(NEWTOY(login, ">1fph:", TOYFLAG_BIN))
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
9
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
10 config LOGIN
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
11 bool "login"
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
12 default y
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
13 help
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
14 usage: login [-p] [-h host] [[-f] username]
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
15
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
16 Establish a new session with the system.
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
17 -p Preserve environment
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
18 -h The name of the remote host for this login
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
19 -f Do not perform authentication
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
20 */
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
21
674
7e846e281e38 New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
22 #define FOR_login
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
23 #include "toys.h"
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
24
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
25 #define LOGIN_TIMEOUT 60
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
26 #define LOGIN_FAIL_TIMEOUT 3
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
27 #define USER_NAME_MAX_SIZE 32
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
28 #define HOSTNAME_SIZE 32
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
29
674
7e846e281e38 New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
30 GLOBALS(
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
31 char *hostname;
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
32 )
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
33
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
34 static void login_timeout_handler(int sig __attribute__((unused)))
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
35 {
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
36 printf("\nLogin timed out after %d seconds.\n", LOGIN_TIMEOUT);
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
37 exit(0);
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
38 }
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
39
642
812afb883392 Minor cleanups, mostly whitespace.
Rob Landley <rob@landley.net>
parents: 637
diff changeset
40 static char *forbid[] = {
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
41 "BASH_ENV", "ENV", "HOME", "IFS", "LD_LIBRARY_PATH", "LD_PRELOAD",
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
42 "LD_TRACE_LOADED_OBJECTS", "LD_BIND_NOW", "LD_AOUT_LIBRARY_PATH",
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
43 "LD_AOUT_PRELOAD", "LD_NOWARN", "LD_KEEPDIR", "SHELL", NULL
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
44 };
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
45
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
46 int verify_password(char * pwd)
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
47 {
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
48 char *pass;
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
49
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
50 if (read_password(toybuf, sizeof(toybuf), "Password: ")) return 1;
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
51 if (!pwd) return 1;
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
52 if (pwd[0] == '!' || pwd[0] == '*') return 1;
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
53
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
54 pass = crypt(toybuf, pwd);
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
55 if (pass && !strcmp(pass, pwd)) return 0;
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
56
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
57 return 1;
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
58 }
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
59
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
60 void read_user(char * buff, int size)
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
61 {
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
62 char hostname[HOSTNAME_SIZE+1];
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
63 int i = 0;
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
64 hostname[HOSTNAME_SIZE] = 0;
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
65 if(!gethostname(hostname, HOSTNAME_SIZE)) fputs(hostname, stdout);
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
66
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
67 fputs(" login: ", stdout);
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
68 fflush(stdout);
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
69
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
70 do {
718
0ed3351d91eb login: Avoid gcc to drop exit condition because of "always false condition".
Jonathan Clairembault <jonathan@clairembault.fr>
parents: 694
diff changeset
71 int c = getchar();
0ed3351d91eb login: Avoid gcc to drop exit condition because of "always false condition".
Jonathan Clairembault <jonathan@clairembault.fr>
parents: 694
diff changeset
72 if (c == EOF) exit(EXIT_FAILURE);
0ed3351d91eb login: Avoid gcc to drop exit condition because of "always false condition".
Jonathan Clairembault <jonathan@clairembault.fr>
parents: 694
diff changeset
73 buff[0] = c;
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
74 } while (isblank(buff[0]));
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
75
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
76 if (buff[0] != '\n') if(!fgets(&buff[1], HOSTNAME_SIZE-1, stdin)) _exit(1);
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
77
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
78 while(i<HOSTNAME_SIZE-1 && isgraph(buff[i])) i++;
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
79 buff[i] = 0;
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
80 }
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
81
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
82 void handle_nologin(void)
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
83 {
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
84 int fd = open("/etc/nologin", O_RDONLY);
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
85 int size;
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
86 if (fd == -1) return;
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
87
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
88 size = readall(fd, toybuf,sizeof(toybuf)-1);
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
89 toybuf[size] = 0;
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
90 if (!size) puts("System closed for routine maintenance\n");
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
91 else puts(toybuf);
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
92
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
93 close(fd);
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
94 fflush(stdout);
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
95 exit(EXIT_FAILURE);
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
96 }
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
97
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
98 void handle_motd(void)
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
99 {
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
100 int fd = open("/etc/motd", O_RDONLY);
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
101 int size;
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
102 if (fd == -1) return;
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
103
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
104 size = readall(fd, toybuf,sizeof(toybuf)-1);
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
105 toybuf[size] = 0;
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
106 puts(toybuf);
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
107
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
108 close(fd);
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
109 fflush(stdout);
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
110 }
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
111
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
112 int change_identity(const struct passwd *pwd)
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
113 {
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
114 if (initgroups(pwd->pw_name,pwd->pw_gid)) return 1;
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
115 if (setgid(pwd->pw_uid)) return 1;
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
116 if (setuid(pwd->pw_uid)) return 1;
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
117
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
118 return 0;
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
119 }
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
120
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
121 void spawn_shell(const char *shell)
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
122 {
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
123 const char * exec_name = strrchr(shell,'/');
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
124 if (exec_name) exec_name++;
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
125 else exec_name = shell;
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
126
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
127 snprintf(toybuf,sizeof(toybuf)-1, "-%s", shell);
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
128 execl(shell, toybuf, NULL);
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
129 error_exit("Failed to spawn shell");
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
130 }
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
131
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
132 void setup_environment(const struct passwd *pwd, int clear_env)
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
133 {
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
134 if (chdir(pwd->pw_dir)) printf("bad home dir: %s\n", pwd->pw_dir);
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
135
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
136 if (clear_env) {
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
137 const char * term = getenv("TERM");
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
138 clearenv();
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
139 if (term) setenv("TERM", term, 1);
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
140 }
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
141
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
142 setenv("USER", pwd->pw_name, 1);
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
143 setenv("LOGNAME", pwd->pw_name, 1);
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
144 setenv("HOME", pwd->pw_dir, 1);
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
145 setenv("SHELL", pwd->pw_shell, 1);
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
146 }
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
147
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
148 void login_main(void)
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
149 {
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
150 int f_flag = toys.optflags & FLAG_f;
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
151 int h_flag = toys.optflags & FLAG_h;
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
152 char username[USER_NAME_MAX_SIZE+1], *pass = NULL, **ss;
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
153 struct passwd * pwd = NULL;
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
154 struct spwd * spwd = NULL;
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
155 int auth_fail_cnt = 0;
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
156
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
157 if (f_flag && toys.optc != 1) error_exit("-f requires username");
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
158
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
159 if (geteuid()) error_exit("not root");
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
160
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
161 if (!isatty(0) || !isatty(1) || !isatty(2)) error_exit("no tty");
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
162
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
163 openlog("login", LOG_PID | LOG_CONS, LOG_AUTH);
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
164 signal(SIGALRM, login_timeout_handler);
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
165 alarm(LOGIN_TIMEOUT);
642
812afb883392 Minor cleanups, mostly whitespace.
Rob Landley <rob@landley.net>
parents: 637
diff changeset
166
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
167 for (ss = forbid; *ss; ss++) unsetenv(*ss);
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
168
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
169 while (1) {
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
170 tcflush(0, TCIFLUSH);
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
171
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
172 username[USER_NAME_MAX_SIZE] = 0;
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
173 if (toys.optargs[0]) strncpy(username, toys.optargs[0], USER_NAME_MAX_SIZE);
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
174 else {
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
175 read_user(username, USER_NAME_MAX_SIZE+1);
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
176 if (username[0] == 0) continue;
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
177 }
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
178
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
179 pwd = getpwnam(username);
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
180 if (!pwd) goto query_pass; // Non-existing user
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
181
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
182 if (pwd->pw_passwd[0] == '!' || pwd->pw_passwd[0] == '*')
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
183 goto query_pass; // Locked account
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
184
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
185 if (f_flag) break; // Pre-authenticated
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
186
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
187 if (!pwd->pw_passwd[0]) break; // Password-less account
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
188
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
189 pass = pwd->pw_passwd;
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
190 if (pwd->pw_passwd[0] == 'x') {
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
191 spwd = getspnam (username);
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
192 if (spwd) pass = spwd->sp_pwdp;
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
193 }
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
194
642
812afb883392 Minor cleanups, mostly whitespace.
Rob Landley <rob@landley.net>
parents: 637
diff changeset
195 query_pass:
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
196 if (!verify_password(pass)) break;
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
197
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
198 f_flag = 0;
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
199 syslog(LOG_WARNING, "invalid password for '%s' on %s %s %s", username,
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
200 ttyname(0), h_flag?"from":"", h_flag?TT.hostname:"");
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
201
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
202 sleep(LOGIN_FAIL_TIMEOUT);
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
203 puts("Login incorrect");
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
204
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
205 if (++auth_fail_cnt == 3)
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
206 error_exit("Maximum number of tries exceeded (%d)\n", auth_fail_cnt);
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
207
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
208 username[0] = 0;
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
209 pwd = NULL;
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
210 spwd = NULL;
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
211 }
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
212
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
213 alarm(0);
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
214
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
215 if (pwd->pw_uid) handle_nologin();
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
216
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
217 if (change_identity(pwd)) error_exit("Failed to change identity");
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
218
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
219 setup_environment(pwd, !(toys.optflags & FLAG_p));
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
220
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
221 handle_motd();
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
222
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
223 syslog(LOG_INFO, "%s logged in on %s %s %s", pwd->pw_name,
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
224 ttyname(0), h_flag?"from":"", h_flag?TT.hostname:"");
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
225
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
226 spawn_shell(pwd->pw_shell);
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
227 }