svn commit: trunk/busybox: docs include libbb loginutils

vda at busybox.net vda at busybox.net
Tue May 8 10:52:19 PDT 2007


Author: vda
Date: 2007-05-08 10:52:17 -0700 (Tue, 08 May 2007)
New Revision: 18586

Log:
cryptpw: new applet (a bit less than 3k added)
(by Thomas Lundquist <lists at zelow.no>)



Modified:
   trunk/busybox/docs/new-applet-HOWTO.txt
   trunk/busybox/include/applets.h
   trunk/busybox/include/libbb.h
   trunk/busybox/include/usage.h
   trunk/busybox/libbb/Kbuild
   trunk/busybox/libbb/chomp.c
   trunk/busybox/loginutils/Config.in
   trunk/busybox/loginutils/Kbuild
   trunk/busybox/loginutils/passwd.c


Changeset:
Modified: trunk/busybox/docs/new-applet-HOWTO.txt
===================================================================
--- trunk/busybox/docs/new-applet-HOWTO.txt	2007-05-08 17:27:17 UTC (rev 18585)
+++ trunk/busybox/docs/new-applet-HOWTO.txt	2007-05-08 17:52:17 UTC (rev 18586)
@@ -6,8 +6,11 @@
 Credits:
 Matt Kraai - initial writeup
 Mark Whitley - the remix
-Thomas Lundquist - Added stuff for the new directory layout.
+Thomas Lundquist - Trying to keep it updated.
 
+When doing this you should consider using the latest svn trunk.
+This is a good thing if you plan to getting it commited into mainline.
+
 Initial Write
 -------------
 
@@ -21,6 +24,10 @@
 
 For a new applet mu, here is the code that would go in mu.c:
 
+(busybox.h already includes most usual header files. You do not need
+#include <stdio.h> etc...)
+
+
 ----begin example code------
 
 /* vi: set sw=4 ts=4: */
@@ -33,7 +40,7 @@
  */
 
 #include "busybox.h"
-#include <other.h>
+#include "other.h"
 
 int mu_main(int argc, char **argv);
 int mu_main(int argc, char **argv)
@@ -69,7 +76,39 @@
 Additionally, if you have any useful, general-purpose functions in your
 applet that could be useful in other applets, consider putting them in libbb.
 
+And it may be possible that some of the other applets uses functions you
+could use. If so, you have to rip the function out of the applet and make
+a libbb function out of it.
 
+Adding a libbb function:
+------------------------
+
+Make a new file named <function_name>.c
+
+----start example code------
+
+#include "libbb.h"
+#include "other.h"
+
+int function(char *a)
+{
+	return *a;
+}
+
+----end example code------
+
+Add <function_name>.o in the right alphabetically sorted place 
+in libbb/Kbuild. You should look at the conditional part of 
+libbb/Kbuild aswell.
+
+You should also try to find a suitable place in include/libbb.h for 
+the function declaration. If not, add it somewhere anyway, with or without
+ifdefs to include or not.
+
+You can look at libbb/Config.in and try to find out if the function is 
+tuneable and add it there if it is.
+
+
 Placement / Directory
 ---------------------
 
@@ -78,9 +117,9 @@
 Make sure you find the appropriate places in the files, the applets are
 sorted alphabetically.
 
-Add the applet to Makefile.in in the chosen directory:
+Add the applet to Kbuild in the chosen directory:
 
-obj-$(CONFIG_MU)               += mu.o
+lib-$(CONFIG_MU)               += mu.o
 
 Add the applet to Config.in in the chosen directory:
 
@@ -119,31 +158,22 @@
 in alphabetical order, or else it will break the binary-search lookup
 algorithm in busybox.c and the Gods of BusyBox smite you. Yea, verily:
 
+Be sure to read the top of applets.h before adding your applet.
+
 	/* all programs above here are alphabetically "less than" 'mu' */
-	#ifdef CONFIG_MU
-		APPLET("mu", mu_main, _BB_DIR_USR_BIN, mu_usage)
-	#endif
+	USE_MU(APPLET(mu, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
 	/* all programs below here are alphabetically "greater than" 'mu' */
 
 
-Documentation
--------------
-
-If you're feeling especially nice, you should also document your applet in the
-docs directory (but nobody ever does that).
-
-Adding some text to docs/Configure.help is a nice start.
-
-
 The Grand Announcement
 ----------------------
 
-Then create a diff -urN of the files you added and/or modified. Typically:
-	<appletdir>/<applet>.c
-	include/usage.c
-	include/applets.h
-	<appletdir>/Makefile.in
-	<appletdir>/config.in
+Then create a diff by adding the new files with svn (remember your libbb files)
+	svn add <where you put it>/mu.c
+eventually also: 
+	svn add libbb/function.c
+then
+	svn diff 
 and send it to the mailing list:
 	busybox at busybox.net
 	http://busybox.net/mailman/listinfo/busybox

Modified: trunk/busybox/include/applets.h
===================================================================
--- trunk/busybox/include/applets.h	2007-05-08 17:27:17 UTC (rev 18585)
+++ trunk/busybox/include/applets.h	2007-05-08 17:52:17 UTC (rev 18586)
@@ -101,6 +101,7 @@
 USE_CPIO(APPLET(cpio, _BB_DIR_BIN, _BB_SUID_NEVER))
 USE_CROND(APPLET(crond, _BB_DIR_USR_SBIN, _BB_SUID_NEVER))
 USE_CRONTAB(APPLET(crontab, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS))
+USE_CRYPTPW(APPLET(cryptpw, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
 USE_CUT(APPLET_NOEXEC(cut, cut, _BB_DIR_USR_BIN, _BB_SUID_NEVER, cut))
 USE_DATE(APPLET(date, _BB_DIR_BIN, _BB_SUID_NEVER))
 USE_DC(APPLET(dc, _BB_DIR_USR_BIN, _BB_SUID_NEVER))

Modified: trunk/busybox/include/libbb.h
===================================================================
--- trunk/busybox/include/libbb.h	2007-05-08 17:27:17 UTC (rev 18585)
+++ trunk/busybox/include/libbb.h	2007-05-08 17:52:17 UTC (rev 18586)
@@ -718,6 +718,7 @@
 
 char *concat_path_file(const char *path, const char *filename);
 char *concat_subpath_file(const char *path, const char *filename);
+/* NB: can violate const-ness (similarly to strchr) */
 char *last_char_is(const char *s, int c);
 
 
@@ -755,6 +756,7 @@
 extern void print_login_issue(const char *issue_file, const char *tty);
 extern void print_login_prompt(void);
 
+extern void crypt_make_salt(char *p, int cnt);
 
 int get_terminal_width_height(const int fd, int *width, int *height);
 

Modified: trunk/busybox/include/usage.h
===================================================================
--- trunk/busybox/include/usage.h	2007-05-08 17:27:17 UTC (rev 18585)
+++ trunk/busybox/include/usage.h	2007-05-08 17:52:17 UTC (rev 18586)
@@ -474,6 +474,13 @@
        "	-d [user]    delete crontab for user\n" \
        "	-c dir       specify crontab directory"
 
+#define cryptpw_trivial_usage \
+       "[-a des|md5] [string]"
+#define cryptpw_full_usage \
+       "Outputs crypted string.\n" \
+       "If string isn't supplied on cmdline, reads it from stdin.\n" \
+       "\nOptions:" \
+       "\n	-a	Algorithm to use (default: md5)"
 
 #define cut_trivial_usage \
        "[OPTION]... [FILE]..."

Modified: trunk/busybox/libbb/Kbuild
===================================================================
--- trunk/busybox/libbb/Kbuild	2007-05-08 17:27:17 UTC (rev 18585)
+++ trunk/busybox/libbb/Kbuild	2007-05-08 17:52:17 UTC (rev 18586)
@@ -21,6 +21,7 @@
 lib-y += crc32.o
 lib-y += create_icmp6_socket.o
 lib-y += create_icmp_socket.o
+lib-y += crypt_make_salt.o
 lib-y += default_error_retval.o
 lib-y += device_open.o
 lib-y += dump.o
@@ -103,6 +104,9 @@
 lib-$(CONFIG_LOSETUP) += loop.o
 lib-$(CONFIG_FEATURE_MTAB_SUPPORT) += mtab.o
 lib-$(CONFIG_PASSWD) += pw_encrypt.o
+lib-$(CONFIG_PASSWD) += crypt_make_salt.o
+lib-$(CONFIG_CRYPTPW) += pw_encrypt.o
+lib-$(CONFIG_CRYPTPW) += crypt_make_salt.o
 lib-$(CONFIG_SULOGIN) += pw_encrypt.o
 lib-$(CONFIG_FEATURE_HTTPD_AUTH_MD5) += pw_encrypt.o
 lib-$(CONFIG_VLOCK) += correct_password.o

Modified: trunk/busybox/libbb/chomp.c
===================================================================
--- trunk/busybox/libbb/chomp.c	2007-05-08 17:27:17 UTC (rev 18585)
+++ trunk/busybox/libbb/chomp.c	2007-05-08 17:52:17 UTC (rev 18586)
@@ -15,5 +15,5 @@
 	char *lc = last_char_is(s, '\n');
 
 	if (lc)
-		*lc = 0;
+		*lc = '\0';
 }

Modified: trunk/busybox/loginutils/Config.in
===================================================================
--- trunk/busybox/loginutils/Config.in	2007-05-08 17:27:17 UTC (rev 18585)
+++ trunk/busybox/loginutils/Config.in	2007-05-08 17:52:17 UTC (rev 18586)
@@ -166,6 +166,12 @@
 	help
 	  With this option passwd will refuse new passwords which are "weak".
 
+config CRYPTPW
+	bool "cryptpw"
+	default n
+	help
+	  Applet for crypting a string.
+
 config SU
 	bool "su"
 	default n

Modified: trunk/busybox/loginutils/Kbuild
===================================================================
--- trunk/busybox/loginutils/Kbuild	2007-05-08 17:27:17 UTC (rev 18585)
+++ trunk/busybox/loginutils/Kbuild	2007-05-08 17:52:17 UTC (rev 18586)
@@ -7,6 +7,7 @@
 lib-y:=
 lib-$(CONFIG_ADDGROUP)	+= addgroup.o
 lib-$(CONFIG_ADDUSER)	+= adduser.o
+lib-$(CONFIG_CRYPTPW)	+= cryptpw.o
 lib-$(CONFIG_GETTY)	+= getty.o
 lib-$(CONFIG_LOGIN)	+= login.o
 lib-$(CONFIG_PASSWD)	+= passwd.o

Modified: trunk/busybox/loginutils/passwd.c
===================================================================
--- trunk/busybox/loginutils/passwd.c	2007-05-08 17:27:17 UTC (rev 18585)
+++ trunk/busybox/loginutils/passwd.c	2007-05-08 17:52:17 UTC (rev 18586)
@@ -12,44 +12,6 @@
 	if (str) memset(str, 0, strlen(str));
 }
 
-
-static int i64c(int i)
-{
-	i &= 0x3f;
-	if (i == 0)
-		return '.';
-	if (i == 1)
-		return '/';
-	if (i < 12)
-		return ('0' - 2 + i);
-	if (i < 38)
-		return ('A' - 12 + i);
-	return ('a' - 38 + i);
-}
-
-
-static void crypt_make_salt(char *p, int cnt)
-{
-	unsigned x = x; /* it's pointless to initialize it anyway :) */
-
-	x += getpid() + time(NULL) + clock();
-	do {
-		/* x = (x*1664525 + 1013904223) % 2^32 generator is lame
-		 * (low-order bit is not "random", etc...),
-		 * but for our purposes it is good enough */
-		x = x*1664525 + 1013904223;
-		/* BTW, Park and Miller's "minimal standard generator" is
-		 * x = x*16807 % ((2^31)-1)
-		 * It has no problem with visibly alternating lowest bit
-		 * but is also weak in cryptographic sense + needs div,
-		 * which needs more code (and slower) on many CPUs */
-		*p++ = i64c(x >> 16);
-		*p++ = i64c(x >> 22);
-	} while (--cnt);
-	*p = '\0';
-}
-
-
 static char* new_password(const struct passwd *pw, uid_t myuid, int algo)
 {
 	char salt[sizeof("$N$XXXXXXXX")]; /* "$N$XXXXXXXX" or "XX" */
@@ -109,18 +71,6 @@
 }
 
 
-#if 0
-static int get_algo(char *a)
-{
-	/* standard: MD5 */
-	int x = 1;
-	if (strcasecmp(a, "des") == 0)
-		x = 0;
-	return x;
-}
-#endif
-
-
 static int update_passwd(const char *filename, const char *username,
 			const char *new_pw)
 {



More information about the busybox-cvs mailing list