annotate toys/other/login.c @ 1326:78a3eaf5555f draft

killall5 - kill all the processes not in its session.
author Ashwini Sharma <ak.ashwini1981@gmail.com>
date Thu, 29 May 2014 08:21:48 -0500
parents faf7117c4489
children 667a65038e93
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.
1156
faf7117c4489 Fix some issues raised (albeit indirectly) by Isaac Dunham.
Rob Landley <rob@landley.net>
parents: 718
diff changeset
17
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
18 -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
19 -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
20 -f Do not perform authentication
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
21 */
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
22
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
23 #define FOR_login
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
24 #include "toys.h"
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
25
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
26 #define LOGIN_TIMEOUT 60
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
27 #define LOGIN_FAIL_TIMEOUT 3
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
28 #define USER_NAME_MAX_SIZE 32
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
29 #define HOSTNAME_SIZE 32
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
30
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
31 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
32 char *hostname;
572
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
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
35 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
36 {
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
37 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
38 exit(0);
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
39 }
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
40
642
812afb883392 Minor cleanups, mostly whitespace.
Rob Landley <rob@landley.net>
parents: 637
diff changeset
41 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
42 "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
43 "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
44 "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
45 };
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
46
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
47 int verify_password(char * pwd)
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
48 {
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
49 char *pass;
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
50
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
51 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
52 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
53 if (pwd[0] == '!' || pwd[0] == '*') return 1;
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
54
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
55 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
56 if (pass && !strcmp(pass, pwd)) return 0;
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
57
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
58 return 1;
572
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
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
61 void read_user(char * buff, int size)
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
62 {
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
63 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
64 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
65 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
66 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
67
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
68 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
69 fflush(stdout);
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
70
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
71 do {
718
0ed3351d91eb login: Avoid gcc to drop exit condition because of "always false condition".
Jonathan Clairembault <jonathan@clairembault.fr>
parents: 694
diff changeset
72 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
73 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
74 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
75 } while (isblank(buff[0]));
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
76
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
77 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
78
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
79 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
80 buff[i] = 0;
572
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
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
83 void handle_nologin(void)
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
84 {
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
85 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
86 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
87 if (fd == -1) return;
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
88
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
89 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
90 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
91 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
92 else puts(toybuf);
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
93
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
94 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
95 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
96 exit(EXIT_FAILURE);
572
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
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
99 void handle_motd(void)
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
100 {
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
101 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
102 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
103 if (fd == -1) return;
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
104
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
105 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
106 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
107 puts(toybuf);
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
108
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
109 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
110 fflush(stdout);
572
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
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
113 void spawn_shell(const char *shell)
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
114 {
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
115 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
116 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
117 else exec_name = shell;
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
118
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
119 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
120 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
121 error_exit("Failed to spawn shell");
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
122 }
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
123
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
124 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
125 {
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
126 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
127
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
128 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
129 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
130 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
131 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
132 }
572
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 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
135 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
136 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
137 setenv("SHELL", pwd->pw_shell, 1);
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
138 }
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
139
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
140 void login_main(void)
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 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
143 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
144 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
145 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
146 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
147 int auth_fail_cnt = 0;
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
148
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
149 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
150
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 if (geteuid()) error_exit("not root");
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
152
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
153 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
154
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
155 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
156 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
157 alarm(LOGIN_TIMEOUT);
642
812afb883392 Minor cleanups, mostly whitespace.
Rob Landley <rob@landley.net>
parents: 637
diff changeset
158
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
159 for (ss = forbid; *ss; ss++) unsetenv(*ss);
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 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
162 tcflush(0, TCIFLUSH);
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
163
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
164 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
165 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
166 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
167 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
168 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
169 }
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
170
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
171 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
172 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
173
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
174 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
175 goto query_pass; // Locked account
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
176
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
177 if (f_flag) break; // Pre-authenticated
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 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
180
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
181 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
182 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
183 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
184 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
185 }
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
186
642
812afb883392 Minor cleanups, mostly whitespace.
Rob Landley <rob@landley.net>
parents: 637
diff changeset
187 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
188 if (!verify_password(pass)) break;
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
189
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
190 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
191 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
192 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
193
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
194 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
195 puts("Login incorrect");
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
196
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
197 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
198 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
199
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
200 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
201 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
202 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
203 }
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 alarm(0);
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
206
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
207 if (pwd->pw_uid) handle_nologin();
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
208
1156
faf7117c4489 Fix some issues raised (albeit indirectly) by Isaac Dunham.
Rob Landley <rob@landley.net>
parents: 718
diff changeset
209 xsetuser(pwd);
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
210
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
211 setup_environment(pwd, !(toys.optflags & FLAG_p));
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 handle_motd();
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 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
216 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
217
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
218 spawn_shell(pwd->pw_shell);
572
8a88a9e3c30b Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff changeset
219 }