1 Star 0 Fork 71

li-shangli/coreutils

forked from src-openEuler/coreutils 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
coreutils-getgrouplist.patch 2.43 KB
一键复制 编辑 原始数据 按行查看 历史
Liquor 提交于 2020-07-29 13:51 . update to 8.32
diff --git a/lib/getugroups.c b/lib/getugroups.c
index 299bae6..8ece29b 100644
--- a/lib/getugroups.c
+++ b/lib/getugroups.c
@@ -19,6 +19,9 @@
#include <config.h>
+/* We do not need this code if getgrouplist(3) is available. */
+#ifndef HAVE_GETGROUPLIST
+
#include "getugroups.h"
#include <errno.h>
@@ -126,3 +129,4 @@ getugroups (int maxcount, gid_t *grouplist, char const *username,
}
#endif /* HAVE_GRP_H */
+#endif /* have getgrouplist */
diff --git a/lib/mgetgroups.c b/lib/mgetgroups.c
index 76474c2..0a9d221 100644
--- a/lib/mgetgroups.c
+++ b/lib/mgetgroups.c
@@ -31,6 +31,7 @@
#endif
#include "getugroups.h"
+#include "xalloc.h"
#include "xalloc-oversized.h"
/* Work around an incompatibility of OS X 10.11: getgrouplist
@@ -121,9 +122,17 @@ mgetgroups (char const *username, gid_t gid, gid_t **groups)
/* else no username, so fall through and use getgroups. */
#endif
- max_n_groups = (username
- ? getugroups (0, NULL, username, gid)
- : getgroups (0, NULL));
+ if (!username)
+ max_n_groups = getgroups(0, NULL);
+ else
+ {
+#ifdef HAVE_GETGROUPLIST
+ max_n_groups = 0;
+ getgrouplist (username, gid, NULL, &max_n_groups);
+#else
+ max_n_groups = getugroups (0, NULL, username, gid);
+#endif
+ }
/* If we failed to count groups because there is no supplemental
group support, then return an array containing just GID.
@@ -145,10 +154,25 @@ mgetgroups (char const *username, gid_t gid, gid_t **groups)
if (g == NULL)
return -1;
- ng = (username
- ? getugroups (max_n_groups, g, username, gid)
- : getgroups (max_n_groups - (gid != (gid_t) -1),
- g + (gid != (gid_t) -1)));
+ if (!username)
+ ng = getgroups (max_n_groups - (gid != (gid_t)-1), g + (gid != (gid_t)-1));
+ else
+ {
+#ifdef HAVE_GETGROUPLIST
+ int e;
+ ng = max_n_groups;
+ while ((e = getgrouplist (username, gid, g, &ng)) == -1
+ && ng > max_n_groups)
+ {
+ max_n_groups = ng;
+ g = xrealloc (g, max_n_groups * sizeof (GETGROUPS_T));
+ }
+ if (e == -1)
+ ng = -1;
+#else
+ ng = getugroups (max_n_groups, g, username, gid);
+#endif
+ }
if (ng < 0)
{
diff --git a/m4/jm-macros.m4 b/m4/jm-macros.m4
index 62777c7..5180243 100644
--- a/m4/jm-macros.m4
+++ b/m4/jm-macros.m4
@@ -82,6 +82,7 @@ AC_DEFUN([coreutils_MACROS],
fchown
fchmod
ftruncate
+ getgrouplist
iswspace
mkfifo
mbrlen
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/li-shangli/coreutils.git
git@gitee.com:li-shangli/coreutils.git
li-shangli
coreutils
coreutils
master

搜索帮助