diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-05-08 17:52:17 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-05-08 17:52:17 +0000 |
commit | 7e84e539de530b2060f0e570fc8f063ed0aaad2f (patch) | |
tree | c03518f2059504a513119cf4d499ccf5c7233f83 | |
parent | 92c0b8222eb50dd35c06e2f1265706b388762234 (diff) | |
download | busybox-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.txt | 74 | ||||
-rw-r--r-- | include/applets.h | 1 | ||||
-rw-r--r-- | include/libbb.h | 2 | ||||
-rw-r--r-- | include/usage.h | 7 | ||||
-rw-r--r-- | libbb/Kbuild | 4 | ||||
-rw-r--r-- | libbb/chomp.c | 2 | ||||
-rw-r--r-- | loginutils/Config.in | 6 | ||||
-rw-r--r-- | loginutils/Kbuild | 1 | ||||
-rw-r--r-- | loginutils/passwd.c | 50 |
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. | |||
6 | Credits: | 6 | Credits: |
7 | Matt Kraai - initial writeup | 7 | Matt Kraai - initial writeup |
8 | Mark Whitley - the remix | 8 | Mark Whitley - the remix |
9 | Thomas Lundquist - Added stuff for the new directory layout. | 9 | Thomas Lundquist - Trying to keep it updated. |
10 | |||
11 | When doing this you should consider using the latest svn trunk. | ||
12 | This is a good thing if you plan to getting it commited into mainline. | ||
10 | 13 | ||
11 | Initial Write | 14 | Initial Write |
12 | ------------- | 15 | ------------- |
@@ -21,6 +24,10 @@ the bb_config.h and appropriate platform specific files are included properly. | |||
21 | 24 | ||
22 | For a new applet mu, here is the code that would go in mu.c: | 25 | For 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 | ||
38 | int mu_main(int argc, char **argv); | 45 | int mu_main(int argc, char **argv); |
39 | int mu_main(int argc, char **argv) | 46 | int mu_main(int argc, char **argv) |
@@ -69,6 +76,38 @@ useful functions in libbb. Use these instead of reinventing the wheel. | |||
69 | Additionally, if you have any useful, general-purpose functions in your | 76 | Additionally, if you have any useful, general-purpose functions in your |
70 | applet that could be useful in other applets, consider putting them in libbb. | 77 | applet that could be useful in other applets, consider putting them in libbb. |
71 | 78 | ||
79 | And it may be possible that some of the other applets uses functions you | ||
80 | could use. If so, you have to rip the function out of the applet and make | ||
81 | a libbb function out of it. | ||
82 | |||
83 | Adding a libbb function: | ||
84 | ------------------------ | ||
85 | |||
86 | Make a new file named <function_name>.c | ||
87 | |||
88 | ----start example code------ | ||
89 | |||
90 | #include "libbb.h" | ||
91 | #include "other.h" | ||
92 | |||
93 | int function(char *a) | ||
94 | { | ||
95 | return *a; | ||
96 | } | ||
97 | |||
98 | ----end example code------ | ||
99 | |||
100 | Add <function_name>.o in the right alphabetically sorted place | ||
101 | in libbb/Kbuild. You should look at the conditional part of | ||
102 | libbb/Kbuild aswell. | ||
103 | |||
104 | You should also try to find a suitable place in include/libbb.h for | ||
105 | the function declaration. If not, add it somewhere anyway, with or without | ||
106 | ifdefs to include or not. | ||
107 | |||
108 | You can look at libbb/Config.in and try to find out if the function is | ||
109 | tuneable and add it there if it is. | ||
110 | |||
72 | 111 | ||
73 | Placement / Directory | 112 | Placement / Directory |
74 | --------------------- | 113 | --------------------- |
@@ -78,9 +117,9 @@ Find the appropriate directory for your new applet. | |||
78 | Make sure you find the appropriate places in the files, the applets are | 117 | Make sure you find the appropriate places in the files, the applets are |
79 | sorted alphabetically. | 118 | sorted alphabetically. |
80 | 119 | ||
81 | Add the applet to Makefile.in in the chosen directory: | 120 | Add the applet to Kbuild in the chosen directory: |
82 | 121 | ||
83 | obj-$(CONFIG_MU) += mu.o | 122 | lib-$(CONFIG_MU) += mu.o |
84 | 123 | ||
85 | Add the applet to Config.in in the chosen directory: | 124 | Add 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 | |||
119 | in alphabetical order, or else it will break the binary-search lookup | 158 | in alphabetical order, or else it will break the binary-search lookup |
120 | algorithm in busybox.c and the Gods of BusyBox smite you. Yea, verily: | 159 | algorithm in busybox.c and the Gods of BusyBox smite you. Yea, verily: |
121 | 160 | ||
161 | Be 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 | ||
129 | Documentation | ||
130 | ------------- | ||
131 | |||
132 | If you're feeling especially nice, you should also document your applet in the | ||
133 | docs directory (but nobody ever does that). | ||
134 | |||
135 | Adding some text to docs/Configure.help is a nice start. | ||
136 | |||
137 | |||
138 | The Grand Announcement | 168 | The Grand Announcement |
139 | ---------------------- | 169 | ---------------------- |
140 | 170 | ||
141 | Then create a diff -urN of the files you added and/or modified. Typically: | 171 | Then 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 | 173 | eventually also: |
144 | include/applets.h | 174 | svn add libbb/function.c |
145 | <appletdir>/Makefile.in | 175 | then |
146 | <appletdir>/config.in | 176 | svn diff |
147 | and send it to the mailing list: | 177 | and 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)) | |||
101 | USE_CPIO(APPLET(cpio, _BB_DIR_BIN, _BB_SUID_NEVER)) | 101 | USE_CPIO(APPLET(cpio, _BB_DIR_BIN, _BB_SUID_NEVER)) |
102 | USE_CROND(APPLET(crond, _BB_DIR_USR_SBIN, _BB_SUID_NEVER)) | 102 | USE_CROND(APPLET(crond, _BB_DIR_USR_SBIN, _BB_SUID_NEVER)) |
103 | USE_CRONTAB(APPLET(crontab, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS)) | 103 | USE_CRONTAB(APPLET(crontab, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS)) |
104 | USE_CRYPTPW(APPLET(cryptpw, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) | ||
104 | USE_CUT(APPLET_NOEXEC(cut, cut, _BB_DIR_USR_BIN, _BB_SUID_NEVER, cut)) | 105 | USE_CUT(APPLET_NOEXEC(cut, cut, _BB_DIR_USR_BIN, _BB_SUID_NEVER, cut)) |
105 | USE_DATE(APPLET(date, _BB_DIR_BIN, _BB_SUID_NEVER)) | 106 | USE_DATE(APPLET(date, _BB_DIR_BIN, _BB_SUID_NEVER)) |
106 | USE_DC(APPLET(dc, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) | 107 | USE_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 | ||
719 | char *concat_path_file(const char *path, const char *filename); | 719 | char *concat_path_file(const char *path, const char *filename); |
720 | char *concat_subpath_file(const char *path, const char *filename); | 720 | char *concat_subpath_file(const char *path, const char *filename); |
721 | /* NB: can violate const-ness (similarly to strchr) */ | ||
721 | char *last_char_is(const char *s, int c); | 722 | char *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 * | |||
755 | extern void print_login_issue(const char *issue_file, const char *tty); | 756 | extern void print_login_issue(const char *issue_file, const char *tty); |
756 | extern void print_login_prompt(void); | 757 | extern void print_login_prompt(void); |
757 | 758 | ||
759 | extern void crypt_make_salt(char *p, int cnt); | ||
758 | 760 | ||
759 | int get_terminal_width_height(const int fd, int *width, int *height); | 761 | int 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 | |||
21 | lib-y += crc32.o | 21 | lib-y += crc32.o |
22 | lib-y += create_icmp6_socket.o | 22 | lib-y += create_icmp6_socket.o |
23 | lib-y += create_icmp_socket.o | 23 | lib-y += create_icmp_socket.o |
24 | lib-y += crypt_make_salt.o | ||
24 | lib-y += default_error_retval.o | 25 | lib-y += default_error_retval.o |
25 | lib-y += device_open.o | 26 | lib-y += device_open.o |
26 | lib-y += dump.o | 27 | lib-y += dump.o |
@@ -103,6 +104,9 @@ lib-$(CONFIG_FEATURE_MOUNT_LOOP) += loop.o | |||
103 | lib-$(CONFIG_LOSETUP) += loop.o | 104 | lib-$(CONFIG_LOSETUP) += loop.o |
104 | lib-$(CONFIG_FEATURE_MTAB_SUPPORT) += mtab.o | 105 | lib-$(CONFIG_FEATURE_MTAB_SUPPORT) += mtab.o |
105 | lib-$(CONFIG_PASSWD) += pw_encrypt.o | 106 | lib-$(CONFIG_PASSWD) += pw_encrypt.o |
107 | lib-$(CONFIG_PASSWD) += crypt_make_salt.o | ||
108 | lib-$(CONFIG_CRYPTPW) += pw_encrypt.o | ||
109 | lib-$(CONFIG_CRYPTPW) += crypt_make_salt.o | ||
106 | lib-$(CONFIG_SULOGIN) += pw_encrypt.o | 110 | lib-$(CONFIG_SULOGIN) += pw_encrypt.o |
107 | lib-$(CONFIG_FEATURE_HTTPD_AUTH_MD5) += pw_encrypt.o | 111 | lib-$(CONFIG_FEATURE_HTTPD_AUTH_MD5) += pw_encrypt.o |
108 | lib-$(CONFIG_VLOCK) += correct_password.o | 112 | lib-$(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 | ||
169 | config CRYPTPW | ||
170 | bool "cryptpw" | ||
171 | default n | ||
172 | help | ||
173 | Applet for crypting a string. | ||
174 | |||
169 | config SU | 175 | config 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 @@ | |||
7 | lib-y:= | 7 | lib-y:= |
8 | lib-$(CONFIG_ADDGROUP) += addgroup.o | 8 | lib-$(CONFIG_ADDGROUP) += addgroup.o |
9 | lib-$(CONFIG_ADDUSER) += adduser.o | 9 | lib-$(CONFIG_ADDUSER) += adduser.o |
10 | lib-$(CONFIG_CRYPTPW) += cryptpw.o | ||
10 | lib-$(CONFIG_GETTY) += getty.o | 11 | lib-$(CONFIG_GETTY) += getty.o |
11 | lib-$(CONFIG_LOGIN) += login.o | 12 | lib-$(CONFIG_LOGIN) += login.o |
12 | lib-$(CONFIG_PASSWD) += passwd.o | 13 | lib-$(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 | |||
16 | static 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 | |||
31 | static 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 | |||
53 | static char* new_password(const struct passwd *pw, uid_t myuid, int algo) | 15 | static 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 | ||
113 | static 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 | |||
124 | static int update_passwd(const char *filename, const char *username, | 74 | static int update_passwd(const char *filename, const char *username, |
125 | const char *new_pw) | 75 | const char *new_pw) |
126 | { | 76 | { |