[Buildroot] Buildroot fails on powerpc with busybox login.c

Bernhard Fischer rep.nop at aon.at
Fri Sep 15 16:32:06 UTC 2006


[trimming CC list]

On Thu, Sep 14, 2006 at 07:16:25PM +0200, Bernhard Fischer wrote:
>On Thu, Sep 14, 2006 at 07:00:12PM +0200, Denis Vlasenko wrote:
>>On Wednesday 13 September 2006 17:44, Bernhard Fischer wrote:
>
>>> r16112 has a partial fix to make it build again. We (e.g. vda ;) should
>>> provide empty bodies for read_or_build_utent() and write_utent() if UTMP
>>> support is disabled. This can go hand in hand with removing the
>>> pointless forward decls for said functions.
>>
>>Done ;)
>
>Thanks for taking care of this.
>cheers,
>Bernhard

I spoke too soon. Turning off UTMP in the config still fails to
compile..

I'm attaching 3 incremental patches:

login.01_of_03.diff
makes it build even if CONFIG_FEATURE_UTMP is turned off.

login.02_of_03.diff
shrink by perusing bb_common_bufsiz1

login.02_of_03.diff
shrink by perusing bb_getopt_ulflags()

Stats:
   text    data     bss     dec     hex filename
   1821       4      32    1857     741 login.o.01
   1809       4      32    1845     735 login.o.02
   1745       4      32    1781     6f5 login.o.03

I compile-tested them and assume that they didn't break anything, but
can't test them at the moment.. If anyone can confirm that it still
works as advertised, then please let me know. I'll try to check them in
during the weekend except somebody raises objections.

PS: I'm well aware that it still is too big. I guess it should fit into
1200 bytes at most. So still room for improvement there..

thanks,
-------------- next part --------------
--- login.c.orig	2006-09-15 18:20:33.000000000 +0200
+++ login.c	2006-09-15 10:22:26.000000000 +0200
@@ -40,7 +40,9 @@
  *	This means that getty should never invoke login with any
  *	command line flags.
  */
+
 static struct utmp utent;
+
 static void read_or_build_utent(int picky)
 {
 	struct utmp *ut;
@@ -97,10 +99,10 @@
 	updwtmp(bb_path_wtmp_file, &utent);
 #endif
 }
-#else /* !CONFIG_FEATURE_UTMP */
-static inline void read_or_build_utent(int) {}
-static inline void write_utent(const char *) {}
-#endif /* !CONFIG_FEATURE_UTMP */
+#else /* !ENABLE_FEATURE_UTMP */
+static inline void read_or_build_utent(int ATTRIBUTE_UNUSED picky) {}
+static inline void write_utent(const char ATTRIBUTE_UNUSED *username) {}
+#endif /* !ENABLE_FEATURE_UTMP */
 
 static void die_if_nologin_and_non_root(int amroot)
 {
@@ -273,8 +275,9 @@
 	read_or_build_utent(!amroot);
 
 	if (opt_host) {
-		if (ENABLE_FEATURE_UTMP)
+		USE_FEATURE_UTMP(
 			safe_strncpy(utent.ut_host, opt_host, sizeof(utent.ut_host));
+		)
 		snprintf(fromhost, sizeof(fromhost)-1, " on `%.100s' from "
 					"`%.200s'", short_tty, opt_host);
 	}
-------------- next part --------------
--- login.c.01	2006-09-15 10:22:26.000000000 +0200
+++ login.c	2006-09-15 11:08:59.000000000 +0200
@@ -130,22 +130,21 @@
 {
 	FILE *fp;
 	int i;
-	char buf[BUFSIZ];
 
 	fp = fopen(bb_path_securetty_file, "r");
 	if (!fp) {
 		/* A missing securetty file is not an error. */
 		return 1;
 	}
-	while (fgets(buf, sizeof(buf)-1, fp)) {
-		for(i = strlen(buf)-1; i>=0; --i) {
-			if (!isspace(buf[i]))
+	while (fgets(bb_common_bufsiz1, sizeof(bb_common_bufsiz1)-1, fp)) {
+		for(i = strlen(bb_common_bufsiz1)-1; i>=0; --i) {
+			if (!isspace(bb_common_bufsiz1[i]))
 				break;
 		}
-		buf[++i] = '\0';
-		if ((buf[0]=='\0') || (buf[0]=='#'))
+		bb_common_bufsiz1[++i] = '\0';
+		if ((bb_common_bufsiz1[0]=='\0') || (bb_common_bufsiz1[0]=='#'))
 			continue;
-		if (strcmp(buf, short_tty) == 0) {
+		if (strcmp(bb_common_bufsiz1, short_tty) == 0) {
 			fclose(fp);
 			return 1;
 		}
-------------- next part --------------
--- login.c.02	2006-09-15 11:08:59.000000000 +0200
+++ login.c	2006-09-15 15:30:46.000000000 +0200
@@ -216,12 +216,14 @@
 	char username[USERNAME_SIZE];
 	const char *tmp;
 	int amroot;
-	int flag;
+	unsigned long opt;
+#define LOGIN_OPT_f (1<<0)
+#define LOGIN_OPT_h (1<<1)
+#define LOGIN_OPT_p (1<<2)
 	int count = 0;
 	struct passwd *pw;
-	int opt_preserve = 0;
-	int opt_fflag = 0;
-	char *opt_host = 0;
+	char *opt_host = NULL;
+	char *opt_user = NULL;
 #ifdef CONFIG_SELINUX
 	security_context_t user_sid = NULL;
 #endif
@@ -231,34 +233,14 @@
 	signal(SIGALRM, alarm_handler);
 	alarm(TIMEOUT);
 
-	while ((flag = getopt(argc, argv, "f:h:p")) != EOF) {
-		switch (flag) {
-		case 'p':
-			opt_preserve = 1;
-			break;
-		case 'f':
-			/*
-			 * username must be a separate token
-			 * (-f root, *NOT* -froot). --marekm
-			 */
-			if (optarg != argv[optind-1])
-				bb_show_usage();
-
-			if (!amroot)	/* Auth bypass only if real UID is zero */
-				bb_error_msg_and_die("-f is for root only");
+	opt = bb_getopt_ulflags(argc, argv, "f:h:p", &opt_user, &opt_host);
 
-			safe_strncpy(username, optarg, sizeof(username));
-			opt_fflag = 1;
-			break;
-		case 'h':
-			opt_host = optarg;
-			break;
-		default:
-			bb_show_usage();
-		}
+	if ((opt & LOGIN_OPT_f)) {
+		if (!amroot)
+			bb_error_msg_and_die("-f is for root only");
+		safe_strncpy(username, opt_user, strlen(opt_user));
 	}
-	if (optind < argc)             /* user from command line (getty) */
-		safe_strncpy(username, argv[optind], sizeof(username));
+	username[USERNAME_SIZE] = 0;
 
 	/* Let's find out and memorize our tty */
 	if (!isatty(0) || !isatty(1) || !isatty(2))
@@ -300,7 +282,7 @@
 		if (pw->pw_passwd[0] == '!' || pw->pw_passwd[0] == '*')
 			goto auth_failed;
 
-		if (opt_fflag)
+		if (opt & LOGIN_OPT_f)
 			break; /* -f USER: success without asking passwd */
 
 		if (pw->pw_uid == 0 && !check_securetty())
@@ -308,14 +290,14 @@
 
 		/* Don't check the password if password entry is empty (!) */
 		if (!pw->pw_passwd[0])
-			break; 
+			break;
 
 		/* authorization takes place here */
 		if (correct_password(pw))
-			break; 
+			break;
 
 auth_failed:
-		opt_fflag = 0;
+		opt ^= LOGIN_OPT_f;
 		bb_do_delay(FAIL_DELAY);
 		puts("Login incorrect");
 		if (++count == 3) {
@@ -384,7 +366,7 @@
 	tmp = pw->pw_shell;
 	if (!tmp || !*tmp)
 		tmp = DEFAULT_SHELL;
-	setup_environment(tmp, 1, !opt_preserve, pw);
+	setup_environment(tmp, 1, !(opt & LOGIN_OPT_p), pw);
 
 	motd();
 	signal(SIGALRM, SIG_DFL);	/* default alarm signal */


More information about the busybox mailing list