Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
1fff03ef
L
libvirt
项目概览
openeuler
/
libvirt
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
L
libvirt
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
1fff03ef
编写于
12月 16, 2011
作者:
D
Daniel P. Berrange
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add virGetGroupName to convert from GID to group name
上级
8c9a2954
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
57 addition
and
0 deletion
+57
-0
src/libvirt_private.syms
src/libvirt_private.syms
+1
-0
src/util/util.c
src/util/util.c
+55
-0
src/util/util.h
src/util/util.h
+1
-0
未找到文件。
src/libvirt_private.syms
浏览文件 @
1fff03ef
...
...
@@ -1112,6 +1112,7 @@ virFindFileInPath;
virFormatMacAddr;
virGenerateMacAddr;
virGetGroupID;
virGetGroupName;
virGetHostname;
virGetUserDirectory;
virGetUserID;
...
...
src/util/util.c
浏览文件 @
1fff03ef
...
...
@@ -2187,6 +2187,56 @@ static char *virGetUserEnt(uid_t uid,
return
ret
;
}
static
char
*
virGetGroupEnt
(
gid_t
gid
)
{
char
*
strbuf
;
char
*
ret
;
struct
group
grbuf
;
struct
group
*
gr
=
NULL
;
long
val
=
sysconf
(
_SC_GETGR_R_SIZE_MAX
);
size_t
strbuflen
=
val
;
int
rc
;
/* sysconf is a hint; if it fails, fall back to a reasonable size */
if
(
val
<
0
)
strbuflen
=
1024
;
if
(
VIR_ALLOC_N
(
strbuf
,
strbuflen
)
<
0
)
{
virReportOOMError
();
return
NULL
;
}
/*
* From the manpage (terrifying but true):
*
* ERRORS
* 0 or ENOENT or ESRCH or EBADF or EPERM or ...
* The given name or gid was not found.
*/
while
((
rc
=
getgrgid_r
(
gid
,
&
grbuf
,
strbuf
,
strbuflen
,
&
gr
))
==
ERANGE
)
{
if
(
VIR_RESIZE_N
(
strbuf
,
strbuflen
,
strbuflen
,
strbuflen
)
<
0
)
{
virReportOOMError
();
VIR_FREE
(
strbuf
);
return
NULL
;
}
}
if
(
rc
!=
0
||
gr
==
NULL
)
{
virReportSystemError
(
rc
,
_
(
"Failed to find group record for gid '%u'"
),
(
unsigned
int
)
gid
);
VIR_FREE
(
strbuf
);
return
NULL
;
}
ret
=
strdup
(
gr
->
gr_name
);
VIR_FREE
(
strbuf
);
if
(
!
ret
)
virReportOOMError
();
return
ret
;
}
char
*
virGetUserDirectory
(
uid_t
uid
)
{
return
virGetUserEnt
(
uid
,
VIR_USER_ENT_DIRECTORY
);
...
...
@@ -2197,6 +2247,11 @@ char *virGetUserName(uid_t uid)
return
virGetUserEnt
(
uid
,
VIR_USER_ENT_NAME
);
}
char
*
virGetGroupName
(
gid_t
gid
)
{
return
virGetGroupEnt
(
gid
);
}
int
virGetUserID
(
const
char
*
name
,
uid_t
*
uid
)
...
...
src/util/util.h
浏览文件 @
1fff03ef
...
...
@@ -236,6 +236,7 @@ int virKillProcess(pid_t pid, int sig);
char
*
virGetUserDirectory
(
uid_t
uid
);
char
*
virGetUserName
(
uid_t
uid
);
char
*
virGetGroupName
(
gid_t
gid
);
int
virGetUserID
(
const
char
*
name
,
uid_t
*
uid
)
ATTRIBUTE_RETURN_CHECK
;
int
virGetGroupID
(
const
char
*
name
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录