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