Mercurial > hg > toybox
annotate toys/other/login.c @ 1640:41efba077b75 draft
Switch a lot of strncpy() calls to xstrncpy().
author | Rob Landley <rob@landley.net> |
---|---|
date | Thu, 01 Jan 2015 16:59:35 -0600 |
parents | 685a0da6ca59 |
children | c0ef9b7976f0 |
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 |
1564
685a0da6ca59
probe for getspnam(), forkpty(), utmpx, replace sethostname()
Isaac Dunham <ibid.ag@gmail.com>
parents:
1354
diff
changeset
|
13 depends on TOYBOX_SHADOW |
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
|
14 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
|
15 usage: login [-p] [-h host] [[-f] username] |
572
8a88a9e3c30b
Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
16 |
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
|
17 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
|
18 |
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
|
19 -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
|
20 -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
|
21 -f Do not perform authentication |
572
8a88a9e3c30b
Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
22 */ |
8a88a9e3c30b
Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
23 |
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
|
24 #define FOR_login |
572
8a88a9e3c30b
Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
25 #include "toys.h" |
8a88a9e3c30b
Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
26 |
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; |
1354 | 32 |
33 int login_timeout, login_fail_timeout; | |
572
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 |
8a88a9e3c30b
Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
36 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
|
37 { |
1354 | 38 printf("\nLogin timed out after %d seconds.\n", TT.login_timeout); |
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
|
39 exit(0); |
572
8a88a9e3c30b
Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
40 } |
8a88a9e3c30b
Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
41 |
642
812afb883392
Minor cleanups, mostly whitespace.
Rob Landley <rob@landley.net>
parents:
637
diff
changeset
|
42 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
|
43 "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
|
44 "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
|
45 "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
|
46 }; |
8a88a9e3c30b
Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
47 |
8a88a9e3c30b
Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
48 int verify_password(char * pwd) |
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 char *pass; |
572
8a88a9e3c30b
Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
51 |
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
|
52 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
|
53 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
|
54 if (pwd[0] == '!' || pwd[0] == '*') return 1; |
572
8a88a9e3c30b
Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
55 |
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
|
56 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
|
57 if (pass && !strcmp(pass, pwd)) return 0; |
572
8a88a9e3c30b
Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
58 |
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
|
59 return 1; |
572
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 |
8a88a9e3c30b
Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
62 void read_user(char * buff, int size) |
8a88a9e3c30b
Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
63 { |
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
|
64 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
|
65 int i = 0; |
1354 | 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 hostname[HOSTNAME_SIZE] = 0; |
1354 | 68 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
|
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 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
|
71 fflush(stdout); |
572
8a88a9e3c30b
Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
72 |
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
|
73 do { |
718
0ed3351d91eb
login: Avoid gcc to drop exit condition because of "always false condition".
Jonathan Clairembault <jonathan@clairembault.fr>
parents:
694
diff
changeset
|
74 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
|
75 if (c == EOF) exit(EXIT_FAILURE); |
1354 | 76 *buff = c; |
77 } while (isblank(*buff)); | |
572
8a88a9e3c30b
Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
78 |
1354 | 79 if (*buff != '\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
|
80 |
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
|
81 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
|
82 buff[i] = 0; |
572
8a88a9e3c30b
Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
83 } |
8a88a9e3c30b
Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
84 |
8a88a9e3c30b
Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
85 void handle_nologin(void) |
8a88a9e3c30b
Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
86 { |
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
|
87 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
|
88 int size; |
1354 | 89 |
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
|
90 if (fd == -1) return; |
572
8a88a9e3c30b
Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
91 |
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
|
92 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
|
93 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
|
94 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
|
95 else puts(toybuf); |
572
8a88a9e3c30b
Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
96 |
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
|
97 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
|
98 fflush(stdout); |
1354 | 99 exit(1); |
572
8a88a9e3c30b
Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
100 } |
8a88a9e3c30b
Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
101 |
8a88a9e3c30b
Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
102 void handle_motd(void) |
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 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
|
105 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
|
106 if (fd == -1) return; |
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 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
|
109 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
|
110 puts(toybuf); |
572
8a88a9e3c30b
Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
111 |
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
|
112 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
|
113 fflush(stdout); |
572
8a88a9e3c30b
Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
114 } |
8a88a9e3c30b
Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
115 |
8a88a9e3c30b
Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
116 void spawn_shell(const char *shell) |
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 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
|
119 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
|
120 else exec_name = shell; |
572
8a88a9e3c30b
Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
121 |
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
|
122 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
|
123 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
|
124 error_exit("Failed to spawn shell"); |
572
8a88a9e3c30b
Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
125 } |
8a88a9e3c30b
Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
126 |
8a88a9e3c30b
Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
127 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
|
128 { |
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
|
129 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
|
130 |
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
|
131 if (clear_env) { |
1354 | 132 const char *term = getenv("TERM"); |
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
|
133 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
|
134 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
|
135 } |
572
8a88a9e3c30b
Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
136 |
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
|
137 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
|
138 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
|
139 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
|
140 setenv("SHELL", pwd->pw_shell, 1); |
572
8a88a9e3c30b
Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
141 } |
8a88a9e3c30b
Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
142 |
8a88a9e3c30b
Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
143 void login_main(void) |
8a88a9e3c30b
Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
144 { |
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
|
145 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
|
146 int h_flag = toys.optflags & FLAG_h; |
1354 | 147 char username[33], *pass = NULL, **ss; |
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
|
148 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
|
149 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
|
150 int auth_fail_cnt = 0; |
572
8a88a9e3c30b
Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
151 |
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
|
152 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
|
153 |
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 if (geteuid()) error_exit("not root"); |
572
8a88a9e3c30b
Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
155 |
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
|
156 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
|
157 |
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
|
158 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
|
159 signal(SIGALRM, login_timeout_handler); |
1354 | 160 alarm(TT.login_timeout = 60); |
642
812afb883392
Minor cleanups, mostly whitespace.
Rob Landley <rob@landley.net>
parents:
637
diff
changeset
|
161 |
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
|
162 for (ss = forbid; *ss; ss++) unsetenv(*ss); |
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 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
|
165 tcflush(0, TCIFLUSH); |
572
8a88a9e3c30b
Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
166 |
1354 | 167 username[sizeof(username)-1] = 0; |
1640
41efba077b75
Switch a lot of strncpy() calls to xstrncpy().
Rob Landley <rob@landley.net>
parents:
1564
diff
changeset
|
168 if (*toys.optargs) xstrncpy(username, *toys.optargs, sizeof(username)); |
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 else { |
1354 | 170 read_user(username, sizeof(username)); |
171 if (!*username) continue; | |
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 } |
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 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
|
175 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
|
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 (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
|
178 goto query_pass; // Locked account |
572
8a88a9e3c30b
Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
179 |
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
|
180 if (f_flag) break; // Pre-authenticated |
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]) break; // Password-less account |
572
8a88a9e3c30b
Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
183 |
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
|
184 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
|
185 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
|
186 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
|
187 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
|
188 } |
572
8a88a9e3c30b
Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
189 |
642
812afb883392
Minor cleanups, mostly whitespace.
Rob Landley <rob@landley.net>
parents:
637
diff
changeset
|
190 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
|
191 if (!verify_password(pass)) break; |
572
8a88a9e3c30b
Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
192 |
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
|
193 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
|
194 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
|
195 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
|
196 |
1354 | 197 sleep(3); |
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 puts("Login incorrect"); |
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 if (++auth_fail_cnt == 3) |
1354 | 201 error_exit("Maximum number of tries exceeded (3)\n"); |
572
8a88a9e3c30b
Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
202 |
1354 | 203 *username = 0; |
204 pwd = 0; | |
205 spwd = 0; | |
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
|
206 } |
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 alarm(0); |
572
8a88a9e3c30b
Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
209 |
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
|
210 if (pwd->pw_uid) handle_nologin(); |
572
8a88a9e3c30b
Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
211 |
1156
faf7117c4489
Fix some issues raised (albeit indirectly) by Isaac Dunham.
Rob Landley <rob@landley.net>
parents:
718
diff
changeset
|
212 xsetuser(pwd); |
572
8a88a9e3c30b
Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
213 |
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
|
214 setup_environment(pwd, !(toys.optflags & FLAG_p)); |
572
8a88a9e3c30b
Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
215 |
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
|
216 handle_motd(); |
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 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
|
219 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
|
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 spawn_shell(pwd->pw_shell); |
572
8a88a9e3c30b
Adding initial version of login.c
Elie De Brauwer <eliedebrauwer@gmail.com>
parents:
diff
changeset
|
222 } |