NuttX has support to /etc/passwd to console nsh login, just like almost all Unix outta here, but a developer called Petro found an issue in the TEA crypto algorithm implementation and fixed it:
https://github.com/apache/incubator-nuttx-apps/pull/1097
Unfortunately after this fixing the Console Login of the NuttX simulador stopped to work. And to make thing worst nobody noticed it until too later (during the NuttX 10.4.0-RC0 release). Then I found the issue and posted about it on NuttX mailing list. Immediately Petro realized it was caused by his Pull Request above and replied my email.
So, I decided to fix it myself. The first challenge was to find where the /etc/passwd was created. Is there some script to create it? After some investigation I found it at boards/sim/sim/sim/src/etc/passwd.
So my idea was run the command “passwd” and change it like we do in the Linux/Unix. So, the first step was to disable the Console Login in the menuconfig:
$ make menuconfig
Application Configuration --->
NSH Library --->
[ ] Console Login
But my nightmare started after doing it because NuttX has many poke-yoke to prevent users making mistakes.
For example: in apps/nshlib/nsh_passwdcmds.c we have at beginning:
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && \
defined(CONFIG_NSH_LOGIN_PASSWD) && \
!defined(CONFIG_FSUTILS_PASSWD_READONLY)
...
#ifndef CONFIG_NSH_DISABLE_USERADD
int cmd_useradd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
{
The problem is we disabled the NSH_LOGIN_PASSWD so all commands related to login will not be compiled: useradd, userdel, passwd…
After removing these “#if defined” I compiled again, but the commands didn’t show up. Then I needed to do the same for apps/nshlib/nsh.h, apps/nshlib/nsh_command.c and apps/nshlib/Makefile.
Finally!!! Now the commands appeared at “nsh>” and I could create the new password to “admin” user:
// Let's see if "passwd" command is available
nsh> ?
help usage: help [-v] [<cmd>]
. cp exec losetup mv rm true usleep
[ cmp exit ln passwd rmdir truncate xd
? dirname false ls poweroff set uname
basename dd free mkdir printf sleep umount
break df help mkfatfs ps source unset
cat dmesg hexdump mkrd pwd test useradd
cd echo kill mount readlink time userdel
Builtin Apps:
sh dumpstack hello nsh gpio
// List all the mounted File Systems
nsh> mount
/bin type binfs
/etc type romfs
/proc type procfs
/tmp type vfat
// Umount /etc since romfs is Read-Only
nsh> umount /etc
// Let's format a RAMDISK and mount it at /etc
nsh> mkfatfs /dev/ram2
nsh> mount -t vfat /dev/ram2 /etc
// Recreate the old /etc/passwd with the same (wrong) pass:
nsh> echo "admin:8Tv+Hbmr3pLddSjtzL0kwC:0:0:/" > /etc/passwd
nsh> cat /etc/passwd
admin:8Tv+Hbmr3pLddSjtzL0kwC:0:0:/
// Create a new password to admin user:
nsh> passwd admin
nsh: passwd: missing required argument(s)
nsh> passwd admin Administrator
nsh> cat /etc/passwd
admin:8Tv+Hbmr3pLVb5HHZgd26D:0:0:/
nsh>
Then I just edited the boards/sim/sim/sim/src/etc/passwd and submitted the PR:
https://github.com/apache/incubator-nuttx/pull/6843