Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
3902f634
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看板
提交
3902f634
编写于
5月 13, 2016
作者:
P
Pavel Hrdina
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
virt-aa-helper: remove replace_string and use virStringReplace instead
Signed-off-by:
N
Pavel Hrdina
<
phrdina@redhat.com
>
上级
9575cb85
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
9 addition
and
67 deletion
+9
-67
src/security/virt-aa-helper.c
src/security/virt-aa-helper.c
+9
-67
未找到文件。
src/security/virt-aa-helper.c
浏览文件 @
3902f634
...
...
@@ -147,62 +147,6 @@ vah_info(const char *str)
fprintf
(
stderr
,
_
(
"%s:
\n
%s%c"
),
progname
,
str
,
'\n'
);
}
/*
* Replace @oldstr in @orig with @repstr
* @len is number of bytes allocated for @orig. Assumes @orig, @oldstr and
* @repstr are null terminated
*/
static
int
replace_string
(
char
*
orig
,
const
size_t
len
,
const
char
*
oldstr
,
const
char
*
repstr
)
{
int
idx
;
char
*
pos
=
NULL
;
char
*
tmp
=
NULL
;
if
((
pos
=
strstr
(
orig
,
oldstr
))
==
NULL
)
{
vah_error
(
NULL
,
0
,
_
(
"could not find replacement string"
));
return
-
1
;
}
if
(
VIR_ALLOC_N_QUIET
(
tmp
,
len
)
<
0
)
{
vah_error
(
NULL
,
0
,
_
(
"could not allocate memory for string"
));
return
-
1
;
}
tmp
[
0
]
=
'\0'
;
idx
=
abs
(
pos
-
orig
);
/* copy everything up to oldstr */
strncat
(
tmp
,
orig
,
idx
);
/* add the replacement string */
if
(
strlen
(
tmp
)
+
strlen
(
repstr
)
>
len
-
1
)
{
vah_error
(
NULL
,
0
,
_
(
"not enough space in target buffer"
));
VIR_FREE
(
tmp
);
return
-
1
;
}
strcat
(
tmp
,
repstr
);
/* add everything after oldstr */
if
(
strlen
(
tmp
)
+
strlen
(
orig
)
-
(
idx
+
strlen
(
oldstr
))
>
len
-
1
)
{
vah_error
(
NULL
,
0
,
_
(
"not enough space in target buffer"
));
VIR_FREE
(
tmp
);
return
-
1
;
}
strncat
(
tmp
,
orig
+
idx
+
strlen
(
oldstr
),
strlen
(
orig
)
-
(
idx
+
strlen
(
oldstr
)));
if
(
virStrcpy
(
orig
,
tmp
,
len
)
==
NULL
)
{
vah_error
(
NULL
,
0
,
_
(
"error replacing string"
));
VIR_FREE
(
tmp
);
return
-
1
;
}
VIR_FREE
(
tmp
);
return
0
;
}
/*
* run an apparmor_parser command
*/
...
...
@@ -340,6 +284,7 @@ create_profile(const char *profile, const char *profile_name,
char
*
pcontent
=
NULL
;
char
*
replace_name
=
NULL
;
char
*
replace_files
=
NULL
;
char
*
tmp
=
NULL
;
const
char
*
template_name
=
"
\n
profile LIBVIRT_TEMPLATE"
;
const
char
*
template_end
=
"
\n
}"
;
int
tlen
,
plen
;
...
...
@@ -412,19 +357,16 @@ create_profile(const char *profile, const char *profile_name,
goto
clean_replace
;
}
if
(
VIR_ALLOC_N_QUIET
(
pcontent
,
plen
)
<
0
)
{
vah_error
(
NULL
,
0
,
_
(
"could not allocate memory for profile"
));
goto
clean_replace
;
}
pcontent
[
0
]
=
'\0'
;
strcpy
(
pcontent
,
tcontent
);
if
(
replace_string
(
pcontent
,
plen
,
template_name
,
replace_name
)
<
0
)
if
(
!
(
pcontent
=
virStringReplace
(
tcontent
,
template_name
,
replace_name
)))
goto
clean_all
;
if
((
virtType
!=
VIR_DOMAIN_VIRT_LXC
)
&&
replace_string
(
pcontent
,
plen
,
template_end
,
replace_files
)
<
0
)
goto
clean_all
;
if
(
virtType
!=
VIR_DOMAIN_VIRT_LXC
)
{
if
(
!
(
tmp
=
virStringReplace
(
pcontent
,
template_end
,
replace_files
)))
goto
clean_all
;
VIR_FREE
(
pcontent
);
pcontent
=
tmp
;
tmp
=
NULL
;
}
/* write the file */
if
((
fd
=
open
(
profile
,
O_CREAT
|
O_EXCL
|
O_WRONLY
,
0644
))
==
-
1
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录