login: previous commit comment was wrong :)
That commit added login script support. Now _this commit_ is a style fix. Sorry....
This commit is contained in:
parent
2e502914b0
commit
942e4291fe
@ -35,11 +35,11 @@ static void setutmp(const char *name, const char *line);
|
||||
static struct utmp utent;
|
||||
#endif
|
||||
|
||||
// login defines
|
||||
#define TIMEOUT 60
|
||||
#define EMPTY_USERNAME_COUNT 10
|
||||
#define USERNAME_SIZE 32
|
||||
|
||||
enum {
|
||||
TIMEOUT = 60,
|
||||
EMPTY_USERNAME_COUNT = 10,
|
||||
USERNAME_SIZE = 32,
|
||||
};
|
||||
|
||||
static int check_nologin(int amroot);
|
||||
|
||||
@ -86,7 +86,7 @@ int login_main(int argc, char **argv)
|
||||
security_context_t user_sid = NULL;
|
||||
#endif
|
||||
|
||||
username[0]=0;
|
||||
username[0] = '\0';
|
||||
amroot = (getuid() == 0);
|
||||
signal(SIGALRM, alarm_handler);
|
||||
alarm(TIMEOUT);
|
||||
@ -119,7 +119,7 @@ int login_main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
if (optind < argc) // user from command line (getty)
|
||||
if (optind < argc) /* user from command line (getty) */
|
||||
safe_strncpy(username, argv[optind], USERNAME_SIZE);
|
||||
|
||||
if (!isatty(0) || !isatty(1) || !isatty(2))
|
||||
@ -139,7 +139,7 @@ int login_main(int argc, char **argv)
|
||||
|
||||
#ifdef CONFIG_FEATURE_UTMP
|
||||
if (amroot)
|
||||
memset ( utent.ut_host, 0, sizeof utent.ut_host );
|
||||
memset(utent.ut_host, 0, sizeof(utent.ut_host));
|
||||
#endif
|
||||
|
||||
if (opt_host) {
|
||||
@ -167,7 +167,8 @@ int login_main(int argc, char **argv)
|
||||
alarmstarted = 1;
|
||||
}
|
||||
|
||||
if (!( pw = getpwnam ( username ))) {
|
||||
pw = getpwnam(username);
|
||||
if (!pw) {
|
||||
pw_copy.pw_name = "UNKNOWN";
|
||||
pw_copy.pw_passwd = "!";
|
||||
opt_fflag = 0;
|
||||
@ -206,7 +207,7 @@ auth_ok:
|
||||
puts("Login incorrect");
|
||||
username[0] = 0;
|
||||
if (++count == 3) {
|
||||
syslog ( LOG_WARNING, "invalid password for `%s'%s\n", pw->pw_name, fromhost);
|
||||
syslog(LOG_WARNING, "invalid password for `%s'%s'\n", pw->pw_name, fromhost);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
@ -225,28 +226,27 @@ auth_ok:
|
||||
safe_strncpy(full_tty, tty, sizeof(full_tty)-1);
|
||||
|
||||
#ifdef CONFIG_SELINUX
|
||||
if (is_selinux_enabled())
|
||||
{
|
||||
if (is_selinux_enabled()) {
|
||||
security_context_t old_tty_sid, new_tty_sid;
|
||||
|
||||
if (get_default_context(username, NULL, &user_sid))
|
||||
{
|
||||
if (get_default_context(username, NULL, &user_sid)) {
|
||||
fprintf(stderr, "Unable to get SID for %s\n", username);
|
||||
exit(1);
|
||||
}
|
||||
if (getfilecon(full_tty, &old_tty_sid) < 0)
|
||||
{
|
||||
fprintf(stderr, "getfilecon(%.100s) failed: %.100s\n", full_tty, strerror(errno));
|
||||
if (getfilecon(full_tty, &old_tty_sid) < 0) {
|
||||
fprintf(stderr, "getfilecon(%.100s) failed: "
|
||||
"%.100s\n", full_tty, strerror(errno));
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (security_compute_relabel(user_sid, old_tty_sid, SECCLASS_CHR_FILE, &new_tty_sid) != 0)
|
||||
{
|
||||
fprintf(stderr, "security_change_sid(%.100s) failed: %.100s\n", full_tty, strerror(errno));
|
||||
if (security_compute_relabel(user_sid, old_tty_sid, SECCLASS_CHR_FILE,
|
||||
&new_tty_sid) != 0) {
|
||||
fprintf(stderr, "security_change_sid(%.100s) failed: "
|
||||
"%.100s\n", full_tty, strerror(errno));
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if(setfilecon(full_tty, new_tty_sid) != 0)
|
||||
{
|
||||
fprintf(stderr, "chsid(%.100s, %s) failed: %.100s\n", full_tty, new_tty_sid, strerror(errno));
|
||||
if (setfilecon(full_tty, new_tty_sid) != 0) {
|
||||
fprintf(stderr, "chsid(%.100s, %s) failed: "
|
||||
"%.100s\n", full_tty, new_tty_sid, strerror(errno));
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
@ -302,7 +302,6 @@ auth_ok:
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int login_prompt(char *buf_name)
|
||||
{
|
||||
char buf[1024];
|
||||
@ -321,7 +320,7 @@ static int login_prompt ( char *buf_name )
|
||||
for (sp = buf; isspace(*sp); sp++) { }
|
||||
for (ep = sp; isgraph(*ep); ep++) { }
|
||||
|
||||
*ep = 0;
|
||||
*ep = '\0';
|
||||
safe_strncpy(buf_name, sp, USERNAME_SIZE);
|
||||
if (buf_name[0])
|
||||
return 1;
|
||||
@ -336,7 +335,8 @@ static int check_nologin ( int amroot )
|
||||
FILE *fp;
|
||||
int c;
|
||||
|
||||
if (( fp = fopen ( bb_path_nologin_file, "r" ))) {
|
||||
fp = fopen(bb_path_nologin_file, "r");
|
||||
if (fp) {
|
||||
while ((c = getc(fp)) != EOF)
|
||||
putchar((c=='\n') ? '\r' : c);
|
||||
|
||||
@ -361,7 +361,8 @@ static int check_tty ( const char *tty )
|
||||
int i;
|
||||
char buf[BUFSIZ];
|
||||
|
||||
if (( fp = fopen ( bb_path_securetty_file, "r" ))) {
|
||||
fp = fopen(bb_path_securetty_file, "r");
|
||||
if (fp) {
|
||||
while (fgets(buf, sizeof(buf)-1, fp)) {
|
||||
for(i = strlen(buf)-1; i>=0; --i) {
|
||||
if (!isspace(buf[i]))
|
||||
@ -405,7 +406,8 @@ static void motd (void)
|
||||
FILE *fp;
|
||||
int c;
|
||||
|
||||
if (( fp = fopen ( bb_path_motd_file, "r" ))) {
|
||||
fp = fopen(bb_path_motd_file, "r");
|
||||
if (fp) {
|
||||
while ((c = getc(fp)) != EOF)
|
||||
putchar(c);
|
||||
fclose(fp);
|
||||
@ -466,13 +468,13 @@ static void checkutmp(int picky)
|
||||
}
|
||||
if (strncmp(line, "/dev/", 5) == 0)
|
||||
line += 5;
|
||||
memset(&utent, 0, sizeof utent);
|
||||
memset(&utent, 0, sizeof(utent));
|
||||
utent.ut_type = LOGIN_PROCESS;
|
||||
utent.ut_pid = pid;
|
||||
strncpy(utent.ut_line, line, sizeof utent.ut_line);
|
||||
strncpy(utent.ut_line, line, sizeof(utent.ut_line));
|
||||
/* XXX - assumes /dev/tty?? */
|
||||
strncpy(utent.ut_id, utent.ut_line + 3, sizeof utent.ut_id);
|
||||
strncpy(utent.ut_user, "LOGIN", sizeof utent.ut_user);
|
||||
strncpy(utent.ut_id, utent.ut_line + 3, sizeof(utent.ut_id));
|
||||
strncpy(utent.ut_user, "LOGIN", sizeof(utent.ut_user));
|
||||
t_tmp = (time_t)utent.ut_time;
|
||||
time(&t_tmp);
|
||||
}
|
||||
@ -490,7 +492,7 @@ static void setutmp(const char *name, const char *line ATTRIBUTE_UNUSED)
|
||||
time_t t_tmp = (time_t)utent.ut_time;
|
||||
|
||||
utent.ut_type = USER_PROCESS;
|
||||
strncpy(utent.ut_user, name, sizeof utent.ut_user);
|
||||
strncpy(utent.ut_user, name, sizeof(utent.ut_user));
|
||||
time(&t_tmp);
|
||||
/* other fields already filled in by checkutmp above */
|
||||
setutent();
|
||||
|
Loading…
x
Reference in New Issue
Block a user