You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ac...@apache.org on 2023/06/27 19:19:03 UTC

[nuttx] branch master updated (b9b615b425 -> b64c029080)

This is an automated email from the ASF dual-hosted git repository.

acassis pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


    from b9b615b425 sched/pthread: fix race condition on pthread_cond_wait()
     new f1f33917f7 libc/pwd: Reuse g_passwd and g_passwd_buffer in getpwbuf
     new b64c029080 libc/pwd: Correct the geos related comment and ddd ROOT_GEOS macro

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 libs/libc/pwd/Make.defs          |  1 +
 libs/libc/pwd/lib_find_pwdfile.c |  3 +-
 libs/libc/pwd/lib_getpwbuf.c     | 62 +++-------------------------------------
 libs/libc/pwd/lib_getpwnam.c     |  2 +-
 libs/libc/pwd/lib_getpwnamr.c    |  2 +-
 libs/libc/pwd/lib_getpwuid.c     |  2 +-
 libs/libc/pwd/lib_getpwuidr.c    |  2 +-
 libs/libc/pwd/lib_pwd.h          |  7 +++--
 libs/libc/pwd/lib_pwd_globals.c  |  4 ---
 9 files changed, 16 insertions(+), 69 deletions(-)


[nuttx] 02/02: libc/pwd: Correct the geos related comment and ddd ROOT_GEOS macro

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit b64c02908021993b6a6b249b4066ddce0741dc25
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Sun Jun 25 19:47:32 2023 +0800

    libc/pwd: Correct the geos related comment and ddd ROOT_GEOS macro
    
    fix the minor issue in https://github.com/apache/nuttx/pull/7998
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 libs/libc/pwd/lib_find_pwdfile.c | 3 ++-
 libs/libc/pwd/lib_getpwnam.c     | 2 +-
 libs/libc/pwd/lib_getpwnamr.c    | 2 +-
 libs/libc/pwd/lib_getpwuid.c     | 2 +-
 libs/libc/pwd/lib_getpwuidr.c    | 2 +-
 libs/libc/pwd/lib_pwd.h          | 5 +++++
 6 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/libs/libc/pwd/lib_find_pwdfile.c b/libs/libc/pwd/lib_find_pwdfile.c
index d2020b7748..a7781631be 100644
--- a/libs/libc/pwd/lib_find_pwdfile.c
+++ b/libs/libc/pwd/lib_find_pwdfile.c
@@ -133,13 +133,14 @@ static int pwd_foreach(pwd_foreach_match_t match, uintptr_t arg,
    *
    * The format of the password file is:
    *
-   *   user:x:uid:uid:home
+   *   user:x:uid:uid:geos:home
    *
    * Where:
    *   user:  User name
    *   x:     Encrypted password
    *   uid:   User ID
    *   uid:   Group ID
+   *   geos:  User information
    *   home:  Login directory
    */
 
diff --git a/libs/libc/pwd/lib_getpwnam.c b/libs/libc/pwd/lib_getpwnam.c
index 61c1b14fd5..8cda336a6a 100644
--- a/libs/libc/pwd/lib_getpwnam.c
+++ b/libs/libc/pwd/lib_getpwnam.c
@@ -71,7 +71,7 @@ FAR struct passwd *getpwnam(FAR const char *name)
       return NULL;
     }
 
-  return getpwbuf(ROOT_UID, ROOT_GID, ROOT_NAME, ROOT_NAME, ROOT_DIR,
+  return getpwbuf(ROOT_UID, ROOT_GID, ROOT_NAME, ROOT_GEOCS, ROOT_DIR,
                   ROOT_SHELL);
 #endif
 }
diff --git a/libs/libc/pwd/lib_getpwnamr.c b/libs/libc/pwd/lib_getpwnamr.c
index 557cf45d3f..eba4798e56 100644
--- a/libs/libc/pwd/lib_getpwnamr.c
+++ b/libs/libc/pwd/lib_getpwnamr.c
@@ -82,7 +82,7 @@ int getpwnam_r(FAR const char *name, FAR struct passwd *pwd, FAR char *buf,
       return 0;
     }
 
-  return getpwbuf_r(ROOT_UID, ROOT_GID, ROOT_NAME, ROOT_NAME, ROOT_DIR,
+  return getpwbuf_r(ROOT_UID, ROOT_GID, ROOT_NAME, ROOT_GEOCS, ROOT_DIR,
                     ROOT_SHELL, pwd, buf, buflen, result);
 #endif
 }
diff --git a/libs/libc/pwd/lib_getpwuid.c b/libs/libc/pwd/lib_getpwuid.c
index f9606d9fa6..582672990a 100644
--- a/libs/libc/pwd/lib_getpwuid.c
+++ b/libs/libc/pwd/lib_getpwuid.c
@@ -70,7 +70,7 @@ FAR struct passwd *getpwuid(uid_t uid)
       return NULL;
     }
 
-  return getpwbuf(ROOT_UID, ROOT_GID, ROOT_NAME, ROOT_NAME, ROOT_DIR,
+  return getpwbuf(ROOT_UID, ROOT_GID, ROOT_NAME, ROOT_GEOCS, ROOT_DIR,
                   ROOT_SHELL);
 #endif
 }
diff --git a/libs/libc/pwd/lib_getpwuidr.c b/libs/libc/pwd/lib_getpwuidr.c
index 593c50b552..7b477cdee2 100644
--- a/libs/libc/pwd/lib_getpwuidr.c
+++ b/libs/libc/pwd/lib_getpwuidr.c
@@ -81,7 +81,7 @@ int getpwuid_r(uid_t uid, FAR struct passwd *pwd, FAR char *buf,
       return 0;
     }
 
-  return getpwbuf_r(ROOT_UID, ROOT_GID, ROOT_NAME, ROOT_NAME, ROOT_DIR,
+  return getpwbuf_r(ROOT_UID, ROOT_GID, ROOT_NAME, ROOT_GEOCS, ROOT_DIR,
                     ROOT_SHELL, pwd, buf, buflen, result);
 #endif
 }
diff --git a/libs/libc/pwd/lib_pwd.h b/libs/libc/pwd/lib_pwd.h
index 7a6a0b843c..582616c3ee 100644
--- a/libs/libc/pwd/lib_pwd.h
+++ b/libs/libc/pwd/lib_pwd.h
@@ -33,9 +33,14 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
+#ifndef CONFIG_LIBC_PASSWD_LINESIZE
+#  define CONFIG_LIBC_PASSWD_LINESIZE 80
+#endif
+
 #define ROOT_NAME  "root"
 #define ROOT_UID   0
 #define ROOT_GID   0
+#define ROOT_GEOCS "root"
 #define ROOT_DIR   "/root"
 #define ROOT_SHELL "/bin/nsh"
 


[nuttx] 01/02: libc/pwd: Reuse g_passwd and g_passwd_buffer in getpwbuf

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit f1f33917f7316ebcbbc9553446953fa668fb52e8
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Sun Jun 25 19:31:06 2023 +0800

    libc/pwd: Reuse g_passwd and g_passwd_buffer in getpwbuf
    
    like other similar functions(e.g. getpwnam and getpwuid)
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 libs/libc/pwd/Make.defs         |  1 +
 libs/libc/pwd/lib_getpwbuf.c    | 62 +++--------------------------------------
 libs/libc/pwd/lib_pwd.h         |  2 --
 libs/libc/pwd/lib_pwd_globals.c |  4 ---
 4 files changed, 5 insertions(+), 64 deletions(-)

diff --git a/libs/libc/pwd/Make.defs b/libs/libc/pwd/Make.defs
index 996555be5a..73b7cb5130 100644
--- a/libs/libc/pwd/Make.defs
+++ b/libs/libc/pwd/Make.defs
@@ -21,6 +21,7 @@
 # Add the pwd C files to the build
 
 CSRCS += lib_getpwnam.c lib_getpwnamr.c lib_getpwuid.c lib_getpwuidr.c
+CSRCS += lib_pwd_globals.c
 
 ifeq ($(CONFIG_LIBC_PASSWD_FILE),y)
 CSRCS += lib_find_pwdfile.c lib_pwd_globals.c
diff --git a/libs/libc/pwd/lib_getpwbuf.c b/libs/libc/pwd/lib_getpwbuf.c
index 5a3fe8f292..7d85f91dd0 100644
--- a/libs/libc/pwd/lib_getpwbuf.c
+++ b/libs/libc/pwd/lib_getpwbuf.c
@@ -24,20 +24,9 @@
 
 #include <nuttx/config.h>
 
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
 #include <pwd.h>
 
 #include "pwd/lib_pwd.h"
-#include "libc.h"
-
-/****************************************************************************
- * Private Data
- ****************************************************************************/
-
-static FAR char *g_buf;
-static FAR struct passwd *g_pwd;
 
 /****************************************************************************
  * Public Functions
@@ -68,51 +57,8 @@ FAR struct passwd *getpwbuf(uid_t uid, gid_t gid, FAR const char *name,
                             FAR const char *gecos, FAR const char *dir,
                             FAR const char *shell)
 {
-  FAR struct passwd *result;
-  FAR char *newbuf;
-  size_t buflen;
-  int err;
-
-  buflen = strlen(name) + 1 + strlen(gecos) + 1 + strlen(dir) + 1 +
-           strlen(shell) + 1;
-
-  newbuf = (FAR char *)lib_realloc(g_buf, buflen);
-
-  if (!newbuf)
-    {
-      err = ENOMEM;
-      goto error;
-    }
-
-  g_buf = newbuf;
-
-  if (!g_pwd)
-    {
-      g_pwd = (FAR struct passwd *)lib_malloc(sizeof(struct passwd));
-    }
-
-  if (!g_pwd)
-    {
-      err = ENOMEM;
-      goto error;
-    }
-
-  err = getpwbuf_r(uid, gid, name, gecos, dir, shell,
-                   g_pwd, g_buf, buflen, &result);
-
-  if (err)
-    {
-      goto error;
-    }
-
-  return result;
-
-error:
-  lib_free(g_pwd);
-  lib_free(g_buf);
-  g_pwd = NULL;
-  g_buf = NULL;
-  set_errno(err);
-
-  return NULL;
+  FAR struct passwd *pwd = NULL;
+  int ret = getpwbuf_r(uid, gid, name, gecos, dir, shell, &g_passwd,
+                       g_passwd_buffer, sizeof(g_passwd_buffer), &pwd);
+  return ret == 0 ? pwd : NULL;
 }
diff --git a/libs/libc/pwd/lib_pwd.h b/libs/libc/pwd/lib_pwd.h
index 6df60732a6..7a6a0b843c 100644
--- a/libs/libc/pwd/lib_pwd.h
+++ b/libs/libc/pwd/lib_pwd.h
@@ -51,12 +51,10 @@ extern "C"
 #define EXTERN extern
 #endif
 
-#ifdef CONFIG_LIBC_PASSWD_FILE
 /* Data for non-reentrant group functions */
 
 EXTERN struct passwd g_passwd;
 EXTERN char g_passwd_buffer[CONFIG_LIBC_PASSWD_LINESIZE];
-#endif
 
 /****************************************************************************
  * Public Function Prototypes
diff --git a/libs/libc/pwd/lib_pwd_globals.c b/libs/libc/pwd/lib_pwd_globals.c
index dc64df1bec..12deca175a 100644
--- a/libs/libc/pwd/lib_pwd_globals.c
+++ b/libs/libc/pwd/lib_pwd_globals.c
@@ -26,8 +26,6 @@
 
 #include "pwd/lib_pwd.h"
 
-#ifdef CONFIG_LIBC_PASSWD_FILE
-
 /****************************************************************************
  * Public Data
  ****************************************************************************/
@@ -40,5 +38,3 @@ char g_passwd_buffer[CONFIG_LIBC_PASSWD_LINESIZE];
 /****************************************************************************
  * Public Functions
  ****************************************************************************/
-
-#endif /* CONFIG_LIBC_GROUP_FILE */