编译
make
代码追踪
入口函数
busybox\libbb\appletlib.c
int main(int argc UNUSED_PARAM, char **argv)
applet_name = bb_basename(applet_name);
run_applet_and_exit(applet_name, argv);
查找name在applet_names当中对应的index
int FAST_FUNC find_applet_by_name(const char *name)
p = bsearch(name, (void*)(ptrdiff_t)1, ARRAY_SIZE(applet_main), 1, applet_name_compare);
const char applet_names[] ALIGN1 = ""
运行对应的applet_no对应的函数
void FAST_FUNC run_applet_no_and_exit(int applet_no, char **argv)
./include/applet_tables.h:604:int (*const applet_main[])(int argc, char **argv) = {
init 为例
int init_main(int argc UNUSED_PARAM, char **argv)
static void parse_inittab(void)
run_actions(RESPAWN | ASKFIRST);
wpid = waitpid(-1, NULL, maybe_WNOHANG);
login为例
int login_main(int argc UNUSED_PARAM, char **argv)
读取/etc/passwd
https://blog.youkuaiyun.com/qq_34556414/article/details/78902662
pw = getpwnam(username);
if (ask_and_check_password(pw) > 0)
启动shell
run_shell(pw->pw_shell, 1, NULL, NULL);
void FAST_FUNC run_shell(const char *shell, int loginshell, const char *command, const char **additional_args)
execv(shell, (char **) args);
如何默认添加密码
-
inittab当中
-::respawn:-/bin/login -f root
+::respawn:-/bin/login
因为-f的话,login.c当中会直接登录
if (opt & LOGIN_OPT_f)
break; /* -f USER: success without asking passwd */ -
/etc/passwd当中,将第二项填入适当的内容,这个使用DES加密的
-root::0:0:root:/root:/bin/sh
+root:zopbXlUyfSXmM:0:0:root:/root:/bin/sh
如何不同的设备使用不同的密码?
需要有一个程序启动的时候生成密码,并且检测/etc/passwd文件,如果passwd不同,则修改/etc/passwd。
可以参考loginutils\passwd.c当中的
static char* new_password(const struct passwd *pw, uid_t myuid, const char *algo)
来产生一个密码
int FAST_FUNC update_passwd(const char *filename,
const char *name,
const char *new_passwd,
const char *member)
来将密码更新到/etc/passwd文件当中
注意可能要重启生效,因为修改的时候,login可能已经读完了/etc/passwd文件。
BusyBox启动流程解析

1864

被折叠的 条评论
为什么被折叠?



