xiaoxiang781216 commented on code in PR #3677:
URL: https://github.com/apache/nuttx-apps/pull/3677#discussion_r3679330317


##########
nshlib/nsh_identity.c:
##########
@@ -381,28 +382,220 @@ int cmd_su(FAR struct nsh_vtbl_s *vtbl, int argc, FAR 
char **argv)
 }
 #endif
 
+#ifndef CONFIG_NSH_DISABLE_ID
+
+/****************************************************************************
+ * Name: nsh_id_format_uid
+ *
+ * Description:
+ *   Format a UID token in Linux id(1) style, e.g. "uid=0(root)".
+ *
+ ****************************************************************************/
+
+static void nsh_id_format_uid(FAR char *buf, size_t buflen,
+                              FAR const char *tag, uid_t uid)
+{
+  FAR struct passwd *pwd = getpwuid(uid);
+
+  if (pwd != NULL && pwd->pw_name != NULL)
+    {
+      snprintf(buf, buflen, "%s=%d(%s)", tag, (int)uid, pwd->pw_name);

Review Comment:
   remove the cast



##########
nshlib/nsh_identity.c:
##########
@@ -381,28 +382,220 @@ int cmd_su(FAR struct nsh_vtbl_s *vtbl, int argc, FAR 
char **argv)
 }
 #endif
 
+#ifndef CONFIG_NSH_DISABLE_ID
+
+/****************************************************************************
+ * Name: nsh_id_format_uid
+ *
+ * Description:
+ *   Format a UID token in Linux id(1) style, e.g. "uid=0(root)".
+ *
+ ****************************************************************************/
+
+static void nsh_id_format_uid(FAR char *buf, size_t buflen,
+                              FAR const char *tag, uid_t uid)
+{
+  FAR struct passwd *pwd = getpwuid(uid);
+
+  if (pwd != NULL && pwd->pw_name != NULL)
+    {
+      snprintf(buf, buflen, "%s=%d(%s)", tag, (int)uid, pwd->pw_name);
+    }
+  else if (uid == 0)
+    {
+      snprintf(buf, buflen, "%s=%d(root)", tag, (int)uid);
+    }
+  else
+    {
+      snprintf(buf, buflen, "%s=%d", tag, (int)uid);

Review Comment:
   ditto



##########
nshlib/nsh_identity.c:
##########
@@ -381,28 +382,220 @@ int cmd_su(FAR struct nsh_vtbl_s *vtbl, int argc, FAR 
char **argv)
 }
 #endif
 
+#ifndef CONFIG_NSH_DISABLE_ID
+
+/****************************************************************************
+ * Name: nsh_id_format_uid
+ *
+ * Description:
+ *   Format a UID token in Linux id(1) style, e.g. "uid=0(root)".
+ *
+ ****************************************************************************/
+
+static void nsh_id_format_uid(FAR char *buf, size_t buflen,
+                              FAR const char *tag, uid_t uid)
+{
+  FAR struct passwd *pwd = getpwuid(uid);
+
+  if (pwd != NULL && pwd->pw_name != NULL)
+    {
+      snprintf(buf, buflen, "%s=%d(%s)", tag, (int)uid, pwd->pw_name);
+    }
+  else if (uid == 0)
+    {
+      snprintf(buf, buflen, "%s=%d(root)", tag, (int)uid);
+    }
+  else
+    {
+      snprintf(buf, buflen, "%s=%d", tag, (int)uid);
+    }
+}
+
+/****************************************************************************
+ * Name: nsh_id_format_gid
+ *
+ * Description:
+ *   Format a GID token in Linux id(1) style, e.g. "gid=0(root)".
+ *
+ ****************************************************************************/
+
+static void nsh_id_format_gid(FAR char *buf, size_t buflen,
+                              FAR const char *tag, gid_t gid)
+{
+  FAR struct group *grp = getgrgid(gid);
+
+  if (grp != NULL && grp->gr_name != NULL)
+    {
+      snprintf(buf, buflen, "%s=%d(%s)", tag, (int)gid, grp->gr_name);

Review Comment:
   remove the cast in ALL places



##########
nshlib/nsh_identity.c:
##########
@@ -381,28 +382,220 @@ int cmd_su(FAR struct nsh_vtbl_s *vtbl, int argc, FAR 
char **argv)
 }
 #endif
 
+#ifndef CONFIG_NSH_DISABLE_ID
+
+/****************************************************************************
+ * Name: nsh_id_format_uid
+ *
+ * Description:
+ *   Format a UID token in Linux id(1) style, e.g. "uid=0(root)".
+ *
+ ****************************************************************************/
+
+static void nsh_id_format_uid(FAR char *buf, size_t buflen,
+                              FAR const char *tag, uid_t uid)
+{
+  FAR struct passwd *pwd = getpwuid(uid);
+
+  if (pwd != NULL && pwd->pw_name != NULL)
+    {
+      snprintf(buf, buflen, "%s=%d(%s)", tag, (int)uid, pwd->pw_name);
+    }
+  else if (uid == 0)
+    {
+      snprintf(buf, buflen, "%s=%d(root)", tag, (int)uid);

Review Comment:
   ditto



##########
testing/ostest/Kconfig:
##########
@@ -124,12 +124,17 @@ config TESTING_OSTEST_MULTIUSER
        bool "Multi-user identity and permission tests"
        default n
        depends on SCHED_USER_IDENTITY
+       select LIBC_PASSWD_FILE

Review Comment:
   depends on



##########
testing/ostest/multiuser.c:
##########
@@ -239,6 +251,26 @@ static int mu_verify_owner(FAR struct mu_ctx_s *ctx, FAR 
const char *path,
   return 0;
 }
 
+static void mu_verify_mode(FAR struct mu_ctx_s *ctx, FAR const char *path,
+                           mode_t mode)
+{
+  struct stat st;
+
+  if (stat(path, &st) != 0)
+    {
+      mu_fail(ctx, "stat(%s) after create errno=%d", path, errno);
+    }
+  else if ((st.st_mode & 0777) != mode)
+    {
+      mu_fail(ctx, "%s mode expected %04o got %04o", path,
+              (unsigned int)mode, (unsigned int)(st.st_mode & 0777));
+    }
+  else
+    {
+      mu_pass("%s mode %04o", path, (unsigned int)mode);

Review Comment:
   remove ALL cast too



##########
nshlib/nsh_identity.c:
##########
@@ -381,28 +382,220 @@ int cmd_su(FAR struct nsh_vtbl_s *vtbl, int argc, FAR 
char **argv)
 }
 #endif
 
+#ifndef CONFIG_NSH_DISABLE_ID
+
+/****************************************************************************
+ * Name: nsh_id_format_uid
+ *
+ * Description:
+ *   Format a UID token in Linux id(1) style, e.g. "uid=0(root)".
+ *
+ ****************************************************************************/
+
+static void nsh_id_format_uid(FAR char *buf, size_t buflen,
+                              FAR const char *tag, uid_t uid)
+{
+  FAR struct passwd *pwd = getpwuid(uid);
+
+  if (pwd != NULL && pwd->pw_name != NULL)
+    {
+      snprintf(buf, buflen, "%s=%d(%s)", tag, (int)uid, pwd->pw_name);
+    }
+  else if (uid == 0)
+    {
+      snprintf(buf, buflen, "%s=%d(root)", tag, (int)uid);
+    }
+  else
+    {
+      snprintf(buf, buflen, "%s=%d", tag, (int)uid);
+    }
+}
+
+/****************************************************************************
+ * Name: nsh_id_format_gid
+ *
+ * Description:
+ *   Format a GID token in Linux id(1) style, e.g. "gid=0(root)".
+ *
+ ****************************************************************************/
+
+static void nsh_id_format_gid(FAR char *buf, size_t buflen,
+                              FAR const char *tag, gid_t gid)
+{
+  FAR struct group *grp = getgrgid(gid);
+
+  if (grp != NULL && grp->gr_name != NULL)
+    {
+      snprintf(buf, buflen, "%s=%d(%s)", tag, (int)gid, grp->gr_name);
+    }
+  else if (gid == 0)
+    {
+      snprintf(buf, buflen, "%s=%d(root)", tag, (int)gid);
+    }
+  else
+    {
+      snprintf(buf, buflen, "%s=%d", tag, (int)gid);
+    }
+}
+
+/****************************************************************************
+ * Name: nsh_id_format_group_value
+ *
+ * Description:
+ *   Format a bare group value for a groups= list, e.g. "0(root)".
+ *
+ ****************************************************************************/
+
+static void nsh_id_format_group_value(FAR char *buf, size_t buflen,
+                                      gid_t gid)
+{
+  FAR struct group *grp = getgrgid(gid);
+
+  if (grp != NULL && grp->gr_name != NULL)
+    {
+      snprintf(buf, buflen, "%d(%s)", (int)gid, grp->gr_name);
+    }
+  else if (gid == 0)
+    {
+      snprintf(buf, buflen, "0(root)");
+    }
+  else
+    {
+      snprintf(buf, buflen, "%d", (int)gid);
+    }
+}
+
+/****************************************************************************
+ * Name: nsh_id_append
+ *
+ * Description:
+ *   Append a formatted token to the id output line.
+ *
+ ****************************************************************************/
+
+static void nsh_id_append(FAR char *line, size_t linelen,
+                          FAR const char *token)
+{
+  size_t len = strlen(line);
+
+  if (len > 0)
+    {
+      strlcat(line, " ", linelen);
+    }
+
+  strlcat(line, token, linelen);
+}
+
+/****************************************************************************
+ * Name: nsh_id_append_groups
+ *
+ * Description:
+ *   Append a Linux-style groups= list to the id output line.
+ *
+ ****************************************************************************/
+
+static void nsh_id_append_groups(FAR char *line, size_t linelen)

Review Comment:
   let's check `#ifdef LIBC_PASSWD_FILE`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to