aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-05-08 17:52:17 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-05-08 17:52:17 +0000
commit7e84e539de530b2060f0e570fc8f063ed0aaad2f (patch)
treec03518f2059504a513119cf4d499ccf5c7233f83
parent92c0b8222eb50dd35c06e2f1265706b388762234 (diff)
downloadbusybox-w32-7e84e539de530b2060f0e570fc8f063ed0aaad2f.tar.gz
busybox-w32-7e84e539de530b2060f0e570fc8f063ed0aaad2f.tar.bz2
busybox-w32-7e84e539de530b2060f0e570fc8f063ed0aaad2f.zip
cryptpw: new applet (a bit less than 3k added)
(by Thomas Lundquist <lists@zelow.no>)
-rw-r--r--docs/new-applet-HOWTO.txt74
-rw-r--r--include/applets.h1
-rw-r--r--include/libbb.h2
-rw-r--r--include/usage.h7
-rw-r--r--libbb/Kbuild4
-rw-r--r--libbb/chomp.c2
-rw-r--r--loginutils/Config.in6
-rw-r--r--loginutils/Kbuild1
-rw-r--r--loginutils/passwd.c50
9 files changed, 74 insertions, 73 deletions
diff --git a/docs/new-applet-HOWTO.txt b/docs/new-applet-HOWTO.txt
index b1e103572..5d8fbe78a 100644
--- a/docs/new-applet-HOWTO.txt
+++ b/docs/new-applet-HOWTO.txt
@@ -6,7 +6,10 @@ This document details the steps you must take to add a new applet to BusyBox.
6Credits: 6Credits:
7Matt Kraai - initial writeup 7Matt Kraai - initial writeup
8Mark Whitley - the remix 8Mark Whitley - the remix
9Thomas Lundquist - Added stuff for the new directory layout. 9Thomas Lundquist - Trying to keep it updated.
10
11When doing this you should consider using the latest svn trunk.
12This is a good thing if you plan to getting it commited into mainline.
10 13
11Initial Write 14Initial Write
12------------- 15-------------
@@ -21,6 +24,10 @@ the bb_config.h and appropriate platform specific files are included properly.
21 24
22For a new applet mu, here is the code that would go in mu.c: 25For a new applet mu, here is the code that would go in mu.c:
23 26
27(busybox.h already includes most usual header files. You do not need
28#include <stdio.h> etc...)
29
30
24----begin example code------ 31----begin example code------
25 32
26/* vi: set sw=4 ts=4: */ 33/* vi: set sw=4 ts=4: */
@@ -33,7 +40,7 @@ For a new applet mu, here is the code that would go in mu.c:
33 */ 40 */
34 41
35#include "busybox.h" 42#include "busybox.h"
36#include <other.h> 43#include "other.h"
37 44
38int mu_main(int argc, char **argv); 45int mu_main(int argc, char **argv);
39int mu_main(int argc, char **argv) 46int mu_main(int argc, char **argv)
@@ -69,6 +76,38 @@ useful functions in libbb. Use these instead of reinventing the wheel.
69Additionally, if you have any useful, general-purpose functions in your 76Additionally, if you have any useful, general-purpose functions in your
70applet that could be useful in other applets, consider putting them in libbb. 77applet that could be useful in other applets, consider putting them in libbb.
71 78
79And it may be possible that some of the other applets uses functions you
80could use. If so, you have to rip the function out of the applet and make
81a libbb function out of it.
82
83Adding a libbb function:
84------------------------
85
86Make a new file named <function_name>.c
87
88----start example code------
89
90#include "libbb.h"
91#include "other.h"
92
93int function(char *a)
94{
95 return *a;
96}
97
98----end example code------
99
100Add <function_name>.o in the right alphabetically sorted place
101in libbb/Kbuild. You should look at the conditional part of
102libbb/Kbuild aswell.
103
104You should also try to find a suitable place in include/libbb.h for
105the function declaration. If not, add it somewhere anyway, with or without
106ifdefs to include or not.
107
108You can look at libbb/Config.in and try to find out if the function is
109tuneable and add it there if it is.
110
72 111
73Placement / Directory 112Placement / Directory
74--------------------- 113---------------------
@@ -78,9 +117,9 @@ Find the appropriate directory for your new applet.
78Make sure you find the appropriate places in the files, the applets are 117Make sure you find the appropriate places in the files, the applets are
79sorted alphabetically. 118sorted alphabetically.
80 119
81Add the applet to Makefile.in in the chosen directory: 120Add the applet to Kbuild in the chosen directory:
82 121
83obj-$(CONFIG_MU) += mu.o 122lib-$(CONFIG_MU) += mu.o
84 123
85Add the applet to Config.in in the chosen directory: 124Add the applet to Config.in in the chosen directory:
86 125
@@ -119,31 +158,22 @@ Next, add an entry to include/applets.h. Be *sure* to keep the list
119in alphabetical order, or else it will break the binary-search lookup 158in alphabetical order, or else it will break the binary-search lookup
120algorithm in busybox.c and the Gods of BusyBox smite you. Yea, verily: 159algorithm in busybox.c and the Gods of BusyBox smite you. Yea, verily:
121 160
161Be sure to read the top of applets.h before adding your applet.
162
122 /* all programs above here are alphabetically "less than" 'mu' */ 163 /* all programs above here are alphabetically "less than" 'mu' */
123 #ifdef CONFIG_MU 164 USE_MU(APPLET(mu, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
124 APPLET("mu", mu_main, _BB_DIR_USR_BIN, mu_usage)
125 #endif
126 /* all programs below here are alphabetically "greater than" 'mu' */ 165 /* all programs below here are alphabetically "greater than" 'mu' */
127 166
128 167
129Documentation
130-------------
131
132If you're feeling especially nice, you should also document your applet in the
133docs directory (but nobody ever does that).
134
135Adding some text to docs/Configure.help is a nice start.
136
137
138The Grand Announcement 168The Grand Announcement
139---------------------- 169----------------------
140 170
141Then create a diff -urN of the files you added and/or modified. Typically: 171Then create a diff by adding the new files with svn (remember your libbb files)
142 <appletdir>/<applet>.c 172 svn add <where you put it>/mu.c
143 include/usage.c 173eventually also:
144 include/applets.h 174 svn add libbb/function.c
145 <appletdir>/Makefile.in 175then
146 <appletdir>/config.in 176 svn diff
147and send it to the mailing list: 177and send it to the mailing list:
148 busybox@busybox.net 178 busybox@busybox.net
149 http://busybox.net/mailman/listinfo/busybox 179 http://busybox.net/mailman/listinfo/busybox
diff --git a/include/applets.h b/include/applets.h
index 67f7db4a6..a7aee3a1d 100644
--- a/include/applets.h
+++ b/include/applets.h
@@ -101,6 +101,7 @@ USE_CP(APPLET_NOEXEC(cp, cp, _BB_DIR_BIN, _BB_SUID_NEVER, cp))
101USE_CPIO(APPLET(cpio, _BB_DIR_BIN, _BB_SUID_NEVER)) 101USE_CPIO(APPLET(cpio, _BB_DIR_BIN, _BB_SUID_NEVER))
102USE_CROND(APPLET(crond, _BB_DIR_USR_SBIN, _BB_SUID_NEVER)) 102USE_CROND(APPLET(crond, _BB_DIR_USR_SBIN, _BB_SUID_NEVER))
103USE_CRONTAB(APPLET(crontab, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS)) 103USE_CRONTAB(APPLET(crontab, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS))
104USE_CRYPTPW(APPLET(cryptpw, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
104USE_CUT(APPLET_NOEXEC(cut, cut, _BB_DIR_USR_BIN, _BB_SUID_NEVER, cut)) 105USE_CUT(APPLET_NOEXEC(cut, cut, _BB_DIR_USR_BIN, _BB_SUID_NEVER, cut))
105USE_DATE(APPLET(date, _BB_DIR_BIN, _BB_SUID_NEVER)) 106USE_DATE(APPLET(date, _BB_DIR_BIN, _BB_SUID_NEVER))
106USE_DC(APPLET(dc, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) 107USE_DC(APPLET(dc, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
diff --git a/include/libbb.h b/include/libbb.h
index be51f2520..32bb3113d 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -718,6 +718,7 @@ extern int bb_parse_mode(const char* s, mode_t* theMode);
718 718
719char *concat_path_file(const char *path, const char *filename); 719char *concat_path_file(const char *path, const char *filename);
720char *concat_subpath_file(const char *path, const char *filename); 720char *concat_subpath_file(const char *path, const char *filename);
721/* NB: can violate const-ness (similarly to strchr) */
721char *last_char_is(const char *s, int c); 722char *last_char_is(const char *s, int c);
722 723
723 724
@@ -755,6 +756,7 @@ extern int index_in_substr_array(const char * const string_array[], const char *
755extern void print_login_issue(const char *issue_file, const char *tty); 756extern void print_login_issue(const char *issue_file, const char *tty);
756extern void print_login_prompt(void); 757extern void print_login_prompt(void);
757 758
759extern void crypt_make_salt(char *p, int cnt);
758 760
759int get_terminal_width_height(const int fd, int *width, int *height); 761int get_terminal_width_height(const int fd, int *width, int *height);
760 762
diff --git a/include/usage.h b/include/usage.h
index afcc4b3d7..eab96011e 100644
--- a/include/usage.h
+++ b/include/usage.h
@@ -474,6 +474,13 @@
474 " -d [user] delete crontab for user\n" \ 474 " -d [user] delete crontab for user\n" \
475 " -c dir specify crontab directory" 475 " -c dir specify crontab directory"
476 476
477#define cryptpw_trivial_usage \
478 "[-a des|md5] [string]"
479#define cryptpw_full_usage \
480 "Outputs crypted string.\n" \
481 "If string isn't supplied on cmdline, reads it from stdin.\n" \
482 "\nOptions:" \
483 "\n -a Algorithm to use (default: md5)"
477 484
478#define cut_trivial_usage \ 485#define cut_trivial_usage \
479 "[OPTION]... [FILE]..." 486 "[OPTION]... [FILE]..."
diff --git a/libbb/Kbuild b/libbb/Kbuild
index 4e6eec38b..eeca7d536 100644
--- a/libbb/Kbuild
+++ b/libbb/Kbuild
@@ -21,6 +21,7 @@ lib-y += copyfd.o
21lib-y += crc32.o 21lib-y += crc32.o
22lib-y += create_icmp6_socket.o 22lib-y += create_icmp6_socket.o
23lib-y += create_icmp_socket.o 23lib-y += create_icmp_socket.o
24lib-y += crypt_make_salt.o
24lib-y += default_error_retval.o 25lib-y += default_error_retval.o
25lib-y += device_open.o 26lib-y += device_open.o
26lib-y += dump.o 27lib-y += dump.o
@@ -103,6 +104,9 @@ lib-$(CONFIG_FEATURE_MOUNT_LOOP) += loop.o
103lib-$(CONFIG_LOSETUP) += loop.o 104lib-$(CONFIG_LOSETUP) += loop.o
104lib-$(CONFIG_FEATURE_MTAB_SUPPORT) += mtab.o 105lib-$(CONFIG_FEATURE_MTAB_SUPPORT) += mtab.o
105lib-$(CONFIG_PASSWD) += pw_encrypt.o 106lib-$(CONFIG_PASSWD) += pw_encrypt.o
107lib-$(CONFIG_PASSWD) += crypt_make_salt.o
108lib-$(CONFIG_CRYPTPW) += pw_encrypt.o
109lib-$(CONFIG_CRYPTPW) += crypt_make_salt.o
106lib-$(CONFIG_SULOGIN) += pw_encrypt.o 110lib-$(CONFIG_SULOGIN) += pw_encrypt.o
107lib-$(CONFIG_FEATURE_HTTPD_AUTH_MD5) += pw_encrypt.o 111lib-$(CONFIG_FEATURE_HTTPD_AUTH_MD5) += pw_encrypt.o
108lib-$(CONFIG_VLOCK) += correct_password.o 112lib-$(CONFIG_VLOCK) += correct_password.o
diff --git a/libbb/chomp.c b/libbb/chomp.c
index eab770760..8ffaff518 100644
--- a/libbb/chomp.c
+++ b/libbb/chomp.c
@@ -15,5 +15,5 @@ void chomp(char *s)
15 char *lc = last_char_is(s, '\n'); 15 char *lc = last_char_is(s, '\n');
16 16
17 if (lc) 17 if (lc)
18 *lc = 0; 18 *lc = '\0';
19} 19}
diff --git a/loginutils/Config.in b/loginutils/Config.in
index e8ab9ec3c..919091ec6 100644
--- a/loginutils/Config.in
+++ b/loginutils/Config.in
@@ -166,6 +166,12 @@ config FEATURE_PASSWD_WEAK_CHECK
166 help 166 help
167 With this option passwd will refuse new passwords which are "weak". 167 With this option passwd will refuse new passwords which are "weak".
168 168
169config CRYPTPW
170 bool "cryptpw"
171 default n
172 help
173 Applet for crypting a string.
174
169config SU 175config SU
170 bool "su" 176 bool "su"
171 default n 177 default n
diff --git a/loginutils/Kbuild b/loginutils/Kbuild
index 6c9d193e1..1b1165a6e 100644
--- a/loginutils/Kbuild
+++ b/loginutils/Kbuild
@@ -7,6 +7,7 @@
7lib-y:= 7lib-y:=
8lib-$(CONFIG_ADDGROUP) += addgroup.o 8lib-$(CONFIG_ADDGROUP) += addgroup.o
9lib-$(CONFIG_ADDUSER) += adduser.o 9lib-$(CONFIG_ADDUSER) += adduser.o
10lib-$(CONFIG_CRYPTPW) += cryptpw.o
10lib-$(CONFIG_GETTY) += getty.o 11lib-$(CONFIG_GETTY) += getty.o
11lib-$(CONFIG_LOGIN) += login.o 12lib-$(CONFIG_LOGIN) += login.o
12lib-$(CONFIG_PASSWD) += passwd.o 13lib-$(CONFIG_PASSWD) += passwd.o
diff --git a/loginutils/passwd.c b/loginutils/passwd.c
index b937ce45e..a323c0a40 100644
--- a/loginutils/passwd.c
+++ b/loginutils/passwd.c
@@ -12,44 +12,6 @@ static void nuke_str(char *str)
12 if (str) memset(str, 0, strlen(str)); 12 if (str) memset(str, 0, strlen(str));
13} 13}
14 14
15
16static int i64c(int i)
17{
18 i &= 0x3f;
19 if (i == 0)
20 return '.';
21 if (i == 1)
22 return '/';
23 if (i < 12)
24 return ('0' - 2 + i);
25 if (i < 38)
26 return ('A' - 12 + i);
27 return ('a' - 38 + i);
28}
29
30
31static void crypt_make_salt(char *p, int cnt)
32{
33 unsigned x = x; /* it's pointless to initialize it anyway :) */
34
35 x += getpid() + time(NULL) + clock();
36 do {
37 /* x = (x*1664525 + 1013904223) % 2^32 generator is lame
38 * (low-order bit is not "random", etc...),
39 * but for our purposes it is good enough */
40 x = x*1664525 + 1013904223;
41 /* BTW, Park and Miller's "minimal standard generator" is
42 * x = x*16807 % ((2^31)-1)
43 * It has no problem with visibly alternating lowest bit
44 * but is also weak in cryptographic sense + needs div,
45 * which needs more code (and slower) on many CPUs */
46 *p++ = i64c(x >> 16);
47 *p++ = i64c(x >> 22);
48 } while (--cnt);
49 *p = '\0';
50}
51
52
53static char* new_password(const struct passwd *pw, uid_t myuid, int algo) 15static char* new_password(const struct passwd *pw, uid_t myuid, int algo)
54{ 16{
55 char salt[sizeof("$N$XXXXXXXX")]; /* "$N$XXXXXXXX" or "XX" */ 17 char salt[sizeof("$N$XXXXXXXX")]; /* "$N$XXXXXXXX" or "XX" */
@@ -109,18 +71,6 @@ static char* new_password(const struct passwd *pw, uid_t myuid, int algo)
109} 71}
110 72
111 73
112#if 0
113static int get_algo(char *a)
114{
115 /* standard: MD5 */
116 int x = 1;
117 if (strcasecmp(a, "des") == 0)
118 x = 0;
119 return x;
120}
121#endif
122
123
124static int update_passwd(const char *filename, const char *username, 74static int update_passwd(const char *filename, const char *username,
125 const char *new_pw) 75 const char *new_pw)
126{ 76{