aboutsummaryrefslogtreecommitdiff
path: root/toys/other/login.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2012-10-08 00:02:30 -0500
committerRob Landley <rob@landley.net>2012-10-08 00:02:30 -0500
commitc0e56edaf256adb6c60c5a052525a1ffbb927901 (patch)
treed6bcc5c181ca46910a12d4dece4b26d6c71be3e1 /toys/other/login.c
parentdc7a77d1940858495f76998f4d13cac9f73e0226 (diff)
downloadtoybox-c0e56edaf256adb6c60c5a052525a1ffbb927901.tar.gz
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.
Diffstat (limited to 'toys/other/login.c')
-rw-r--r--toys/other/login.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/toys/other/login.c b/toys/other/login.c
index 8c542a7e..a9e7562c 100644
--- a/toys/other/login.c
+++ b/toys/other/login.c
@@ -21,6 +21,7 @@ config LOGIN
-f Do not perform authentication
*/
+#define FOR_login
#include "toys.h"
#define LOGIN_TIMEOUT 60
@@ -28,10 +29,9 @@ config LOGIN
#define USER_NAME_MAX_SIZE 32
#define HOSTNAME_SIZE 32
-DEFINE_GLOBALS(
+GLOBALS(
char *hostname;
)
-#define TT this.login
static void login_timeout_handler(int sig __attribute__((unused)))
{
@@ -162,9 +162,8 @@ void setup_environment(const struct passwd *pwd, int clear_env)
void login_main(void)
{
- int f_flag = (toys.optflags & 4) >> 2;
- int p_flag = (toys.optflags & 2) >> 1;
- int h_flag = toys.optflags & 1;
+ int f_flag = toys.optflags & FLAG_f;
+ int h_flag = toys.optflags & FLAG_h;
char username[USER_NAME_MAX_SIZE+1], *pass = NULL, **ss;
struct passwd * pwd = NULL;
struct spwd * spwd = NULL;
@@ -215,7 +214,7 @@ query_pass:
f_flag = 0;
syslog(LOG_WARNING, "invalid password for '%s' on %s %s %s", username,
- ttyname(0), (h_flag)?"from":"", (h_flag)?TT.hostname:"");
+ ttyname(0), h_flag?"from":"", h_flag?TT.hostname:"");
sleep(LOGIN_FAIL_TIMEOUT);
puts("Login incorrect");
@@ -234,12 +233,12 @@ query_pass:
if (change_identity(pwd)) error_exit("Failed to change identity");
- setup_environment(pwd, !p_flag);
+ setup_environment(pwd, !(toys.optflags & FLAG_p));
handle_motd();
syslog(LOG_INFO, "%s logged in on %s %s %s", pwd->pw_name,
- ttyname(0), (h_flag)?"from":"", (h_flag)?TT.hostname:"");
+ ttyname(0), h_flag?"from":"", h_flag?TT.hostname:"");
spawn_shell(pwd->pw_shell);
}