login: make /etc/nologin support configurable. -240 bytes if not selected.
This commit is contained in:
parent
637c975098
commit
f312e32662
@ -943,12 +943,10 @@ extern const char bb_str_default[];
|
|||||||
extern const char bb_hexdigits_upcase[];
|
extern const char bb_hexdigits_upcase[];
|
||||||
|
|
||||||
extern const char bb_path_mtab_file[];
|
extern const char bb_path_mtab_file[];
|
||||||
extern const char bb_path_nologin_file[];
|
|
||||||
extern const char bb_path_passwd_file[];
|
extern const char bb_path_passwd_file[];
|
||||||
extern const char bb_path_shadow_file[];
|
extern const char bb_path_shadow_file[];
|
||||||
extern const char bb_path_gshadow_file[];
|
extern const char bb_path_gshadow_file[];
|
||||||
extern const char bb_path_group_file[];
|
extern const char bb_path_group_file[];
|
||||||
extern const char bb_path_securetty_file[];
|
|
||||||
extern const char bb_path_motd_file[];
|
extern const char bb_path_motd_file[];
|
||||||
extern const char bb_path_wtmp_file[];
|
extern const char bb_path_wtmp_file[];
|
||||||
extern const char bb_dev_null[];
|
extern const char bb_dev_null[];
|
||||||
|
@ -34,8 +34,6 @@ const char bb_path_passwd_file[] = "/etc/passwd";
|
|||||||
const char bb_path_shadow_file[] = "/etc/shadow";
|
const char bb_path_shadow_file[] = "/etc/shadow";
|
||||||
const char bb_path_group_file[] = "/etc/group";
|
const char bb_path_group_file[] = "/etc/group";
|
||||||
const char bb_path_gshadow_file[] = "/etc/gshadow";
|
const char bb_path_gshadow_file[] = "/etc/gshadow";
|
||||||
const char bb_path_nologin_file[] = "/etc/nologin";
|
|
||||||
const char bb_path_securetty_file[] = "/etc/securetty";
|
|
||||||
const char bb_path_motd_file[] = "/etc/motd";
|
const char bb_path_motd_file[] = "/etc/motd";
|
||||||
const char bb_dev_null[] = "/dev/null";
|
const char bb_dev_null[] = "/dev/null";
|
||||||
const char bb_busybox_exec_path[] = CONFIG_BUSYBOX_EXEC_PATH;
|
const char bb_busybox_exec_path[] = CONFIG_BUSYBOX_EXEC_PATH;
|
||||||
|
@ -136,6 +136,14 @@ config LOGIN_SCRIPTS
|
|||||||
Enable this if you want login to execute $LOGIN_PRE_SUID_SCRIPT
|
Enable this if you want login to execute $LOGIN_PRE_SUID_SCRIPT
|
||||||
just prior to switching from root to logged-in user.
|
just prior to switching from root to logged-in user.
|
||||||
|
|
||||||
|
config FEATURE_NOLOGIN
|
||||||
|
bool "Support for /etc/nologin"
|
||||||
|
default y
|
||||||
|
depends on LOGIN
|
||||||
|
help
|
||||||
|
The file /etc/nologin is used by (some versions of) login(1).
|
||||||
|
If it exists, non-root logins are prohibited.
|
||||||
|
|
||||||
config FEATURE_SECURETTY
|
config FEATURE_SECURETTY
|
||||||
bool "Support for /etc/securetty"
|
bool "Support for /etc/securetty"
|
||||||
default y
|
default y
|
||||||
|
@ -100,15 +100,16 @@ static void write_utent(struct utmp *utptr, const char *username)
|
|||||||
#define write_utent(utptr, username) ((void)0)
|
#define write_utent(utptr, username) ((void)0)
|
||||||
#endif /* !ENABLE_FEATURE_UTMP */
|
#endif /* !ENABLE_FEATURE_UTMP */
|
||||||
|
|
||||||
|
#if ENABLE_FEATURE_NOLOGIN
|
||||||
static void die_if_nologin_and_non_root(int amroot)
|
static void die_if_nologin_and_non_root(int amroot)
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
if (access(bb_path_nologin_file, F_OK))
|
if (access("/etc/nologin", F_OK))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
fp = fopen(bb_path_nologin_file, "r");
|
fp = fopen("/etc/nologin", "r");
|
||||||
if (fp) {
|
if (fp) {
|
||||||
while ((c = getc(fp)) != EOF)
|
while ((c = getc(fp)) != EOF)
|
||||||
putchar((c=='\n') ? '\r' : c);
|
putchar((c=='\n') ? '\r' : c);
|
||||||
@ -118,17 +119,20 @@ static void die_if_nologin_and_non_root(int amroot)
|
|||||||
puts("\r\nSystem closed for routine maintenance\r");
|
puts("\r\nSystem closed for routine maintenance\r");
|
||||||
if (!amroot)
|
if (!amroot)
|
||||||
exit(1);
|
exit(1);
|
||||||
puts("\r\n[Disconnect bypassed -- root login allowed.]\r");
|
puts("\r\n[Disconnect bypassed -- root login allowed]\r");
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
static ALWAYS_INLINE void die_if_nologin_and_non_root(int amroot) {}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if ENABLE_FEATURE_SECURETTY
|
#if ENABLE_FEATURE_SECURETTY
|
||||||
static int check_securetty(void)
|
static int check_securetty(void)
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
int i;
|
int i;
|
||||||
char buf[BUFSIZ];
|
char buf[256];
|
||||||
|
|
||||||
fp = fopen(bb_path_securetty_file, "r");
|
fp = fopen("/etc/securetty", "r");
|
||||||
if (!fp) {
|
if (!fp) {
|
||||||
/* A missing securetty file is not an error. */
|
/* A missing securetty file is not an error. */
|
||||||
return 1;
|
return 1;
|
||||||
@ -139,7 +143,7 @@ static int check_securetty(void)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
buf[++i] = '\0';
|
buf[++i] = '\0';
|
||||||
if ((buf[0]=='\0') || (buf[0]=='#'))
|
if (!buf[0] || (buf[0] == '#'))
|
||||||
continue;
|
continue;
|
||||||
if (strcmp(buf, short_tty) == 0) {
|
if (strcmp(buf, short_tty) == 0) {
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
@ -150,7 +154,7 @@ static int check_securetty(void)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
static inline int check_securetty(void) { return 1; }
|
static ALWAYS_INLINE int check_securetty(void) { return 1; }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void get_username_or_die(char *buf, int size_buf)
|
static void get_username_or_die(char *buf, int size_buf)
|
||||||
@ -313,7 +317,7 @@ int login_main(int argc, char **argv)
|
|||||||
|
|
||||||
write_utent(&utent, username);
|
write_utent(&utent, username);
|
||||||
|
|
||||||
#ifdef CONFIG_SELINUX
|
#if ENABLE_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;
|
||||||
|
|
||||||
@ -368,7 +372,7 @@ int login_main(int argc, char **argv)
|
|||||||
|
|
||||||
if (pw->pw_uid == 0)
|
if (pw->pw_uid == 0)
|
||||||
syslog(LOG_INFO, "root login%s", fromhost);
|
syslog(LOG_INFO, "root login%s", fromhost);
|
||||||
#ifdef CONFIG_SELINUX
|
#if ENABLE_SELINUX
|
||||||
/* well, a simple setexeccon() here would do the job as well,
|
/* well, a simple setexeccon() here would do the job as well,
|
||||||
* but let's play the game for now */
|
* but let's play the game for now */
|
||||||
set_current_security_context(user_sid);
|
set_current_security_context(user_sid);
|
||||||
|
Loading…
Reference in New Issue
Block a user