comparison toys/other/login.c @ 1156:faf7117c4489 draft

Fix some issues raised (albeit indirectly) by Isaac Dunham. POLL_IN defined as a constant by some libc. Factor out login.c's change_identity() to xwrap.c as xsetuser(). Replace xsetuid() with xsetuser() Put a space between argument globals and non-argument globals. TT starts zeroed, don't need to re-zero entries in it. STDIN_FILENO has been 0 since 1969, even DOS copied that. Just say 0. Added an xchroot() using xchdir() to lib/xwrap.c. Remove endgrent() call until somebody can explain why it was there.
author Rob Landley <rob@landley.net>
date Mon, 23 Dec 2013 06:49:38 -0600
parents 0ed3351d91eb
children 667a65038e93
comparison
equal deleted inserted replaced
1155:63f8c7fa94d7 1156:faf7117c4489
12 default y 12 default y
13 help 13 help
14 usage: login [-p] [-h host] [[-f] username] 14 usage: login [-p] [-h host] [[-f] username]
15 15
16 Establish a new session with the system. 16 Establish a new session with the system.
17
17 -p Preserve environment 18 -p Preserve environment
18 -h The name of the remote host for this login 19 -h The name of the remote host for this login
19 -f Do not perform authentication 20 -f Do not perform authentication
20 */ 21 */
21 22
105 toybuf[size] = 0; 106 toybuf[size] = 0;
106 puts(toybuf); 107 puts(toybuf);
107 108
108 close(fd); 109 close(fd);
109 fflush(stdout); 110 fflush(stdout);
110 }
111
112 int change_identity(const struct passwd *pwd)
113 {
114 if (initgroups(pwd->pw_name,pwd->pw_gid)) return 1;
115 if (setgid(pwd->pw_uid)) return 1;
116 if (setuid(pwd->pw_uid)) return 1;
117
118 return 0;
119 } 111 }
120 112
121 void spawn_shell(const char *shell) 113 void spawn_shell(const char *shell)
122 { 114 {
123 const char * exec_name = strrchr(shell,'/'); 115 const char * exec_name = strrchr(shell,'/');
212 204
213 alarm(0); 205 alarm(0);
214 206
215 if (pwd->pw_uid) handle_nologin(); 207 if (pwd->pw_uid) handle_nologin();
216 208
217 if (change_identity(pwd)) error_exit("Failed to change identity"); 209 xsetuser(pwd);
218 210
219 setup_environment(pwd, !(toys.optflags & FLAG_p)); 211 setup_environment(pwd, !(toys.optflags & FLAG_p));
220 212
221 handle_motd(); 213 handle_motd();
222 214