NSH: Add logic for the case where the passwd file is read-only. ROMFS image needs to be marked as const, or it will end up in RAM.

This commit is contained in:
Gregory Nutt
2016-01-20 13:05:25 -06:00
parent 3dad8a29a2
commit 681bfa2605
8 changed files with 27 additions and 10 deletions

View File

@@ -16,6 +16,11 @@ config FSUTILS_PASSWD_PATH
string "Path to the passwd file" string "Path to the passwd file"
default "/etc/passwd" default "/etc/passwd"
config FSUTILS_PASSWD_READONLY
bool "Read-only /etc/passwd file?"
default n
depends on FS_WRITABLE
config FSUTILS_PASSWD_IOBUFFER_SIZE config FSUTILS_PASSWD_IOBUFFER_SIZE
int "Allocated I/O buffer size" int "Allocated I/O buffer size"
default 512 default 512

View File

@@ -46,11 +46,13 @@ ifeq ($(CONFIG_FSUTILS_PASSWD),y)
ifeq ($(CONFIG_FS_READABLE),y) ifeq ($(CONFIG_FS_READABLE),y)
CSRCS += passwd_verify.c passwd_find.c passwd_encrypt.c CSRCS += passwd_verify.c passwd_find.c passwd_encrypt.c
ifeq ($(CONFIG_FS_WRITABLE),y) ifeq ($(CONFIG_FS_WRITABLE),y)
ifneq ($(CONFIG_FSUTILS_PASSWD_READONLY),y)
CSRCS += passwd_adduser.c passwd_deluser.c passwd_update.c passwd_append.c CSRCS += passwd_adduser.c passwd_deluser.c passwd_update.c passwd_append.c
CSRCS += passwd_delete.c passwd_lock.c CSRCS += passwd_delete.c passwd_lock.c
endif endif
endif endif
endif endif
endif
AOBJS = $(ASRCS:.S=$(OBJEXT)) AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT)) COBJS = $(CSRCS:.c=$(OBJEXT))

View File

@@ -40,8 +40,11 @@
* Included Files * Included Files
****************************************************************************/ ****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/compiler.h> #include <nuttx/compiler.h>
#if defined(CONFIG_FS_WRITABLE) && defined(CONFIG_FSUTILS_PASSWD_READONLY)
/**************************************************************************** /****************************************************************************
* Public Function Prototypes * Public Function Prototypes
****************************************************************************/ ****************************************************************************/
@@ -122,4 +125,5 @@ int passwd_update(FAR const char *username, FAR const char *password);
int passwd_verify(FAR const char *username, FAR const char *password); int passwd_verify(FAR const char *username, FAR const char *password);
#endif /* CONFIG_FS_WRITABLE && CONFIG_FSUTILS_PASSWD_READONLY */
#endif /* __APPS_INCLUDE_FSUTILS_PASSWD_H */ #endif /* __APPS_INCLUDE_FSUTILS_PASSWD_H */

View File

@@ -379,7 +379,7 @@ config NSH_DISABLE_NSLOOKUP
config NSH_DISABLE_PASSWD config NSH_DISABLE_PASSWD
bool "Disable passwd" bool "Disable passwd"
default y default y
depends on FSUTILS_PASSWD depends on FSUTILS_PASSWD && FS_WRITABLE && !FSUTILS_PASSWD_READONLY
config NSH_DISABLE_POWEROFF config NSH_DISABLE_POWEROFF
bool "Disable poweroff" bool "Disable poweroff"
@@ -475,12 +475,12 @@ config NSH_DISABLE_URLENCODE
config NSH_DISABLE_USERADD config NSH_DISABLE_USERADD
bool "Disable useradd" bool "Disable useradd"
default y default y
depends on FSUTILS_PASSWD depends on FSUTILS_PASSWD && FS_WRITABLE && !FSUTILS_PASSWD_READONLY
config NSH_DISABLE_USERDEL config NSH_DISABLE_USERDEL
bool "Disable userdel" bool "Disable userdel"
default y default y
depends on FSUTILS_PASSWD depends on FSUTILS_PASSWD && FS_WRITABLE && !FSUTILS_PASSWD_READONLY
config NSH_DISABLE_USLEEP config NSH_DISABLE_USLEEP
bool "Disable usleep" bool "Disable usleep"

View File

@@ -1045,7 +1045,8 @@ int cmd_lsmod(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
int cmd_mksmartfs(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); int cmd_mksmartfs(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
# endif # endif
# endif /* CONFIG_FS_SMARTFS */ # endif /* CONFIG_FS_SMARTFS */
# if defined(CONFIG_FSUTILS_PASSWD) && defined(CONFIG_FS_WRITABLE) # if defined(CONFIG_FSUTILS_PASSWD) && defined(CONFIG_FS_WRITABLE) && \
!defined(CONFIG_FSUTILS_PASSWD_READONLY)
# ifndef CONFIG_NSH_DISABLE_USERADD # ifndef CONFIG_NSH_DISABLE_USERADD
int cmd_useradd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); int cmd_useradd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
# endif # endif

View File

@@ -352,7 +352,8 @@ static const struct cmdmap_s g_cmdmap[] =
#endif #endif
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && \ #if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && \
defined(CONFIG_FS_WRITABLE) && defined(CONFIG_FSUTILS_PASSWD) defined(CONFIG_FS_WRITABLE) && defined(CONFIG_FSUTILS_PASSWD) && \
!defined(CONFIG_FSUTILS_PASSWD_READONLY)
# ifndef CONFIG_NSH_DISABLE_PASSWD # ifndef CONFIG_NSH_DISABLE_PASSWD
{ "passwd", cmd_passwd, 3, 3, "<username> <password>" }, { "passwd", cmd_passwd, 3, 3, "<username> <password>" },
# endif # endif
@@ -480,7 +481,8 @@ static const struct cmdmap_s g_cmdmap[] =
#endif #endif
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && \ #if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && \
defined(CONFIG_FS_WRITABLE) && defined(CONFIG_FSUTILS_PASSWD) defined(CONFIG_FS_WRITABLE) && defined(CONFIG_FSUTILS_PASSWD) && \
!defined(CONFIG_FSUTILS_PASSWD_READONLY)
# ifndef CONFIG_NSH_DISABLE_USERADD # ifndef CONFIG_NSH_DISABLE_USERADD
{ "useradd", cmd_useradd, 3, 3, "<username> <password>" }, { "useradd", cmd_useradd, 3, 3, "<username> <password>" },
# endif # endif

View File

@@ -45,7 +45,8 @@
#include "nsh_console.h" #include "nsh_console.h"
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && \ #if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && \
defined(CONFIG_FS_WRITABLE) && defined(CONFIG_FSUTILS_PASSWD) defined(CONFIG_FS_WRITABLE) && defined(CONFIG_FSUTILS_PASSWD) && \
!defined(CONFIG_FSUTILS_PASSWD_READONLY)
/**************************************************************************** /****************************************************************************
* Public Functions * Public Functions
@@ -115,4 +116,5 @@ int cmd_passwd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
#endif /* !CONFIG_NSH_DISABLE_USERADD */ #endif /* !CONFIG_NSH_DISABLE_USERADD */
#endif /* !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && #endif /* !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 &&
* CONFIG_FS_WRITABLE && CONFIG_FSUTILS_PASSWD */ * CONFIG_FS_WRITABLE && CONFIG_FSUTILS_PASSWD &&
* !CONFIG_FSUTILS_PASSWD_READONLY */

View File

@@ -1,4 +1,4 @@
unsigned char romfs_img[] = { const unsigned char romfs_img[] = {
0x2d, 0x72, 0x6f, 0x6d, 0x31, 0x66, 0x73, 0x2d, 0x00, 0x00, 0x01, 0x50, 0x2d, 0x72, 0x6f, 0x6d, 0x31, 0x66, 0x73, 0x2d, 0x00, 0x00, 0x01, 0x50,
0x9f, 0x13, 0x82, 0x87, 0x4e, 0x53, 0x48, 0x49, 0x6e, 0x69, 0x74, 0x56, 0x9f, 0x13, 0x82, 0x87, 0x4e, 0x53, 0x48, 0x49, 0x6e, 0x69, 0x74, 0x56,
0x6f, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x49, 0x6f, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x49,
@@ -86,4 +86,5 @@ unsigned char romfs_img[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00 0x00, 0x00, 0x00, 0x00
}; };
unsigned int romfs_img_len = 1024;
const unsigned int romfs_img_len = 1024;