[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    [BusyBox] Oops on last patch
From:       Joshua Jackson <busybox () vortech ! net>
Date:       2003-05-30 5:14:49
[Download RAW message or body]

There was an extra debugging printf left in the last patch... here is a clean 
version:


 
--
Joshua Jackson
Vortech Consulting, LLC
http://www.vortech.net
["busybox2.patch" (text/x-diff)]

diff -uNr busybox/include/libbb.h busybox-coyote/include/libbb.h
--- busybox/include/libbb.h	2003-03-19 04:11:53.000000000 -0500
+++ busybox-coyote/include/libbb.h	2003-04-29 14:03:13.000000000 -0400
@@ -32,6 +32,8 @@
 
 #include <netdb.h>
 
+#include <termios.h>
+
 #ifdef DMALLOC
 #include <dmalloc.h>
 #endif
@@ -418,7 +420,7 @@
 } llist_t;
 extern llist_t *llist_add_to(llist_t *old_head, char *new_item);
 
-void print_login_issue(const char *issue_file, const char *tty);
+void print_login_issue(const char *issue_file, const char *tty, struct termios *tp);
 void print_login_prompt(void);
 
 #endif /* __LIBCONFIG_H__ */

--- busybox/libbb/login.c	2003-05-13 09:28:25.000000000 -0400
+++ busybox-coyote/libbb/login.c	2003-04-29 14:07:47.000000000 -0400
@@ -26,24 +26,23 @@
 
 #include <sys/utsname.h>
 #include <time.h>
+#include <termios.h>
+#include <utmp.h>
 
 #define LOGIN " login: "
 
 static char fmtstr_d[] = { "%A, %d %B %Y" };
 static char fmtstr_t[] = { "%H:%M:%S" };
 
-void print_login_issue(const char *issue_file, const char *tty)
+void print_login_issue(const char *issue_file, const char *tty, struct termios *tp)
 {
 	FILE *fd;
 	int c;
-	char buf[256];
-	time_t t;
 	struct utsname uts;
 
-	time(&t);
 	uname(&uts);
 
-	puts("");	/* start a new line */
+	(void) write(1, "\r\n", 2);
 
 	if ((fd = fopen(issue_file, "r"))) {
 		while ((c = fgetc(fd)) != EOF) {
@@ -51,63 +50,95 @@
 				c = fgetc(fd);
 
 				switch (c) {
-					case 's':
-						fputs(uts.sysname, stdout);
-						break;
-
-					case 'n':
-						fputs(uts.nodename, stdout);
-						break;
-
-					case 'r':
-						fputs(uts.release, stdout);
-						break;
-
-					case 'v':
-						fputs(uts.version, stdout);
-						break;
-
-					case 'm':
-						fputs(uts.machine, stdout);
-						break;
-
-					case 'D':
-					case 'o':
-						getdomainname(buf, sizeof(buf));
-						buf[sizeof(buf) - 1] = '\0';
-						fputs(buf, stdout);
-						break;
-
-					case 'd':
-						strftime(buf, sizeof(buf), fmtstr_d, localtime(&t));
-						fputs(buf, stdout);
-						break;
-
-					case 't':
-						strftime(buf, sizeof(buf), fmtstr_t, localtime(&t));
-						fputs(buf, stdout);
-						break;
-
-					case 'h':
-						gethostname(buf, sizeof(buf));
-						fputs(buf, stdout);
-						break;
-
-					case 'l':
-						printf("%s", tty);
-						break;
+				case 's':
+					(void) printf("%s", uts.sysname);
+					break;
+
+				case 'n':
+					(void) printf("%s", uts.nodename);
+					break;
+
+				case 'r':
+					(void) printf("%s", uts.release);
+					break;
+
+				case 'v':
+					(void) printf("%s", uts.version);
+					break;
+
+				case 'm':
+					(void) printf("%s", uts.machine);
+					break;
+
+				case 'o':
+				{
+					char domainname[256];
+
+					getdomainname(domainname, sizeof(domainname));
+					domainname[sizeof(domainname) - 1] = '\0';
+					printf("%s", domainname);
+				}
+					break;
+
+				case 'd':
+				case 't':
+				{
+					char *weekday[] = { "Sun", "Mon", "Tue", "Wed", "Thu",
+						"Fri", "Sat"
+					};
+					char *month[] = { "Jan", "Feb", "Mar", "Apr", "May",
+						"Jun", "Jul", "Aug", "Sep", "Oct",
+						"Nov", "Dec"
+					};
+					time_t now;
+					struct tm *tm;
+
+					(void) time(&now);
+					tm = localtime(&now);
+
+					if (c == 'd')
+						(void) printf("%s %s %d  %d",
+									  weekday[tm->tm_wday],
+									  month[tm->tm_mon], tm->tm_mday,
+									  tm->tm_year <
+									  70 ? tm->tm_year +
+									  2000 : tm->tm_year + 1900);
+					else
+						(void) printf("%02d:%02d:%02d", tm->tm_hour,
+									  tm->tm_min, tm->tm_sec);
+
+					break;
+				}
 
-					default:
-						putchar(c);
+				case 'l':
+					(void) printf("%s", tty);
+					break;
+
+				case 'u':
+				case 'U':
+				{
+					int users = 0;
+					struct utmp *ut;
+
+					setutent();
+					while ((ut = getutent()))
+						if (ut->ut_type == USER_PROCESS)
+							users++;
+					endutent();
+					printf("%d ", users);
+					if (c == 'U')
+						printf((users == 1) ? "user" : "users");
+					break;
+				}
+				default:
+					(void) putchar(c);
 				}
 			} else
-				putchar(c);
+				(void) putchar(c);
 		}
-
-		puts("");	/* start a new line */
 		fflush(stdout);
 
-		fclose(fd);
+		(void) fclose(fd);
 	}
 }
 
diff -uNr busybox/loginutils/getty.c busybox-coyote/loginutils/getty.c
--- busybox/loginutils/getty.c	2003-03-19 04:12:20.000000000 -0500
+++ busybox-coyote/loginutils/getty.c	2003-04-29 14:03:13.000000000 -0400
@@ -750,7 +750,15 @@
 static void do_prompt(struct options *op, struct termio *tp)
 {
 #ifdef	ISSUE					/* optional: show /etc/issue */
-	print_login_issue(op->issue, op->tty);
+	int oflag;
+
+	oflag = tp->c_oflag;	/* save current setting */
+	tp->c_oflag |= (ONLCR | OPOST);	/* map NL in output to CR-NL */
+	(void) ioctl(0, TCSETAW, tp);
+	print_login_issue(op->issue, op->tty, tp);
+	tp->c_oflag = oflag;	/* restore settings */
+	(void) ioctl(0, TCSETAW, tp);	/* wait till output is gone */
+
 #endif
 	print_login_prompt();
 }
diff -uNr busybox/loginutils/passwd.c busybox-coyote/loginutils/passwd.c
--- busybox/loginutils/passwd.c	2003-03-19 04:12:20.000000000 -0500
+++ busybox-coyote/loginutils/passwd.c	2003-04-29 14:15:02.000000000 -0400
@@ -140,7 +140,7 @@
 	char *name;
 	char *myname;
 	int flag;
-	int algo = 0;				/* -a - password algorithm */
+	int algo = 1;				/* -a - password algorithm */
 	int lflg = 0;				/* -l - lock account */
 	int uflg = 0;				/* -u - unlock account */
 	int dflg = 0;				/* -d - delete password */
diff -uNr busybox/networking/ipcalc.c busybox-coyote/networking/ipcalc.c
--- busybox/networking/ipcalc.c	2003-03-19 04:12:38.000000000 -0500
+++ busybox-coyote/networking/ipcalc.c	2003-05-29 16:49:30.000000000 -0400
@@ -33,10 +33,26 @@
 	return 0x000000FF;	/* Class A */
 }
 
+static int get_prefix(unsigned long netmask)
+{
+	unsigned long t; 
+	int ret = 0;
+
+	for (t = 0; t < 32; t++) {
+		if (htonl(netmask) & (0x80000000 >> t)) {
+			ret ++;
+		} else {
+			break;
+		}
+	}	
+	return ret;
+}
+
 #define NETMASK   0x01
 #define BROADCAST 0x02
 #define NETWORK   0x04
 #define HOSTNAME  0x08
+#define NETPREFIX 0x10
 #define SILENT    0x80
 
 int ipcalc_main(int argc, char **argv)
@@ -44,16 +62,20 @@
 	unsigned char mode = 0;
 
 	unsigned long netmask = 0;
+	unsigned long netprefix = 0;
 	unsigned long broadcast = 0;
 	unsigned long network = 0;
 	unsigned long ipaddr = 0;
 
-	int opt = 0;
+	int opt = 0, have_netmask = 0;
+
+	char *ipstr, *prefixstr;
 
 	struct option long_options[] = {
 		{"netmask", no_argument, NULL, 'n'},
 		{"broadcast", no_argument, NULL, 'b'},
 		{"network", no_argument, NULL, 'w'},
+		{"prefix", no_argument, NULL, 'p'},
 #ifdef CONFIG_FEATURE_IPCALC_FANCY
 		{"hostname", no_argument, NULL, 'h'},
 		{"silent", no_argument, NULL, 's'},
@@ -64,9 +86,9 @@
 
 	while ((opt = getopt_long(argc, argv,
 #ifdef CONFIG_FEATURE_IPCALC_FANCY
-							  "nbwhs",
+							  "nbwphs",
 #else
-							  "nbw",
+							  "nbwp",
 #endif
 							  long_options, NULL)) != EOF) {
 		if (opt == 'n')
@@ -75,6 +97,8 @@
 			mode |= BROADCAST;
 		else if (opt == 'w')
 			mode |= NETWORK;
+		else if (opt == 'p')
+			mode |= NETPREFIX;
 #ifdef CONFIG_FEATURE_IPCALC_FANCY
 		else if (opt == 'h')
 			mode |= HOSTNAME;
@@ -86,7 +110,7 @@
 		}
 	}
 
-	if (mode & (BROADCAST | NETWORK)) {
+	if (mode & (BROADCAST | NETWORK | NETPREFIX)) {
 		if (argc - optind > 2) {
 			bb_show_usage();
 		}
@@ -96,16 +120,50 @@
 		}
 	}
 
-	ipaddr = inet_addr(argv[optind]);
+	prefixstr = ipstr = argv[optind];
+
+	while(*prefixstr) {
+		if (*prefixstr == '/') {
+			*prefixstr = (char)0;
+			prefixstr++;
+			if (*prefixstr) {
+				netprefix = atol(prefixstr);
+				if (netprefix > 32) {
+					IPCALC_MSG(bb_error_msg_and_die("bad IP prefix: %s\n", prefixstr),
+						exit(EXIT_FAILURE));
+				}
+				if (netprefix) {
+					netmask = 0x80000000;
+					netprefix--;
+					while(netprefix) {
+						netmask = 0x80000000 | (netmask >> 1);
+						netprefix--;
+					}
+					netmask = htonl(netmask);
+				}
+				/* Even if it was 0, we will signify that we have a netmask. This allows */
+				/* for specification of default routes, etc which have a 0 netmask/prefix */
+				have_netmask = 1;	
+			}
+			break;
+		}
+		prefixstr++;
+	}				
+
+	ipaddr = inet_addr(ipstr);
 
 	if (ipaddr == INADDR_NONE) {
 		IPCALC_MSG(bb_error_msg_and_die("bad IP address: %s\n", argv[optind]),
 				   exit(EXIT_FAILURE));
 	}
 
-
 	if (argc - optind == 2) {
+		if (have_netmask == 1) {
+			IPCALC_MSG(bb_error_msg_and_die("Both prefix and netmask were specified, use one or the other.\n"),
+				exit(EXIT_FAILURE));
+		}
 		netmask = inet_addr(argv[optind + 1]);
+		have_netmask = 1;
 	}
 
 	if (ipaddr == INADDR_NONE) {
@@ -113,8 +171,7 @@
 				   exit(EXIT_FAILURE));
 	}
 
-	/* JHC - If the netmask wasn't provided then calculate it */
-	if (!netmask) {
+	if (!have_netmask) {
 		netmask = get_netmask(ipaddr);
 	}
 
@@ -131,6 +188,11 @@
 		network = ipaddr & netmask;
 		printf("NETWORK=%s\n", inet_ntoa((*(struct in_addr *) &network)));
 	}
+
+	if (mode & NETPREFIX) {
+		printf("PREFIX=%i\n", get_prefix(netmask));
+	}
+
 #ifdef CONFIG_FEATURE_IPCALC_FANCY
 	if (mode & HOSTNAME) {
 		struct hostent *hostinfo;
diff -uNr busybox/networking/telnetd.c busybox-coyote/networking/telnetd.c
--- busybox/networking/telnetd.c	2003-04-25 08:32:37.000000000 -0400
+++ busybox-coyote/networking/telnetd.c	2003-04-29 14:03:19.000000000 -0400
@@ -297,7 +297,7 @@
 		/*termbuf.c_lflag &= ~ICANON;*/
 		tcsetattr(0, TCSANOW, &termbuf);
 
-		print_login_issue(issuefile, NULL);
+		print_login_issue(issuefile, NULL, &termbuf);
 
 		/* exec shell, with correct argv and env */
 		execv(loginpath, (char *const *)argv_init);


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic