Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
cc83cda0
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看板
提交
cc83cda0
编写于
1月 10, 2008
作者:
M
Mark McLoughlin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
make use of virFileMakePath(), virFileBuildPath() and virRun().
上级
fc11528f
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
20 addition
and
111 deletion
+20
-111
ChangeLog
ChangeLog
+5
-0
src/iptables.c
src/iptables.c
+15
-111
未找到文件。
ChangeLog
浏览文件 @
cc83cda0
Thu Jan 10 13:49:01 GMT 2008 Mark McLoughlin <markmc@redhat.com>
* src/iptables.c: make use of virFileMakePath(),
virFileBuildPath() and virRun().
Thu Jan 10 13:48:01 GMT 2008 Mark McLoughlin <markmc@redhat.com>
* src/iptables.c: Fix compile error in --with-iptables-dir code
...
...
src/iptables.c
浏览文件 @
cc83cda0
...
...
@@ -44,6 +44,7 @@
#include "internal.h"
#include "iptables.h"
#include "util.h"
#define qemudLog(level, msg...) fprintf(stderr, msg)
...
...
@@ -52,11 +53,6 @@ enum {
REMOVE
};
enum
{
WITH_ERRORS
=
0
,
NO_ERRORS
};
typedef
struct
{
char
*
rule
;
...
...
@@ -135,60 +131,6 @@ writeRules(const char *path,
return
0
;
}
static
int
ensureDir
(
const
char
*
path
)
{
struct
stat
st
;
char
parent
[
PATH_MAX
];
char
*
p
;
int
err
;
if
(
stat
(
path
,
&
st
)
>=
0
)
return
0
;
strncpy
(
parent
,
path
,
PATH_MAX
);
parent
[
PATH_MAX
-
1
]
=
'\0'
;
if
(
!
(
p
=
strrchr
(
parent
,
'/'
)))
return
EINVAL
;
if
(
p
==
parent
)
return
EPERM
;
*
p
=
'\0'
;
if
((
err
=
ensureDir
(
parent
)))
return
err
;
if
(
mkdir
(
path
,
0700
)
<
0
&&
errno
!=
EEXIST
)
return
errno
;
return
0
;
}
static
int
buildDir
(
const
char
*
table
,
char
*
path
,
int
maxlen
)
{
if
(
snprintf
(
path
,
maxlen
,
IPTABLES_DIR
"/%s"
,
table
)
>=
maxlen
)
return
EINVAL
;
else
return
0
;
}
static
int
buildPath
(
const
char
*
table
,
const
char
*
chain
,
char
*
path
,
int
maxlen
)
{
if
(
snprintf
(
path
,
maxlen
,
IPTABLES_DIR
"/%s/%s.chain"
,
table
,
chain
)
>=
maxlen
)
return
EINVAL
;
else
return
0
;
}
#endif
/* IPTABLES_DIR */
static
void
...
...
@@ -235,7 +177,7 @@ iptRulesAppend(iptRules *rules,
{
int
err
;
if
((
err
=
ensureDir
(
rules
->
dir
)))
if
((
err
=
virFileMakePath
(
rules
->
dir
)))
return
err
;
if
((
err
=
writeRules
(
rules
->
path
,
rules
->
rules
,
rules
->
nrules
)))
...
...
@@ -332,10 +274,10 @@ iptRulesNew(const char *table,
rules
->
nrules
=
0
;
#ifdef IPTABLES_DIR
if
(
buildDir
(
table
,
rules
->
dir
,
sizeof
(
rules
->
dir
))
)
if
(
virFileBuildPath
(
IPTABLES_DIR
,
table
,
NULL
,
rules
->
dir
,
sizeof
(
rules
->
dir
))
<
0
)
goto
error
;
if
(
buildPath
(
table
,
chain
,
rules
->
path
,
sizeof
(
rules
->
path
))
)
if
(
virFileBuildPath
(
rules
->
dir
,
chain
,
".chain"
,
rules
->
path
,
sizeof
(
rules
->
path
))
<
0
)
goto
error
;
#endif
/* IPTABLES_DIR */
...
...
@@ -346,55 +288,12 @@ iptRulesNew(const char *table,
return
NULL
;
}
static
int
iptablesSpawn
(
int
errors
,
char
*
const
*
argv
)
{
pid_t
pid
,
ret
;
int
status
;
int
null
=
-
1
;
if
(
errors
==
NO_ERRORS
&&
(
null
=
open
(
_PATH_DEVNULL
,
O_RDONLY
))
<
0
)
return
errno
;
pid
=
fork
();
if
(
pid
==
-
1
)
{
if
(
errors
==
NO_ERRORS
)
close
(
null
);
return
errno
;
}
if
(
pid
==
0
)
{
/* child */
if
(
errors
==
NO_ERRORS
)
{
dup2
(
null
,
STDIN_FILENO
);
dup2
(
null
,
STDOUT_FILENO
);
dup2
(
null
,
STDERR_FILENO
);
close
(
null
);
}
execvp
(
argv
[
0
],
argv
);
_exit
(
1
);
}
if
(
errors
==
NO_ERRORS
)
close
(
null
);
while
((
ret
=
waitpid
(
pid
,
&
status
,
0
)
==
-
1
)
&&
errno
==
EINTR
);
if
(
ret
==
-
1
)
return
errno
;
if
(
errors
==
NO_ERRORS
)
return
0
;
else
return
(
WIFEXITED
(
status
)
&&
WEXITSTATUS
(
status
)
==
0
)
?
0
:
EINVAL
;
}
static
int
iptablesAddRemoveChain
(
iptRules
*
rules
,
int
action
)
{
char
**
argv
;
int
retval
=
ENOMEM
;
int
n
;
int
n
,
status
;
n
=
1
+
/* /sbin/iptables */
2
+
/* --table foo */
...
...
@@ -420,7 +319,10 @@ iptablesAddRemoveChain(iptRules *rules, int action)
if
(
!
(
argv
[
n
++
]
=
strdup
(
rules
->
chain
)))
goto
error
;
retval
=
iptablesSpawn
(
NO_ERRORS
,
argv
);
if
(
virRun
(
NULL
,
argv
,
&
status
)
<
0
)
retval
=
errno
;
retval
=
0
;
error:
if
(
argv
)
{
...
...
@@ -508,8 +410,10 @@ iptablesAddRemoveRule(iptRules *rules, int action, const char *arg, ...)
(
retval
=
iptablesAddRemoveChain
(
rules
,
action
)))
goto
error
;
if
((
retval
=
iptablesSpawn
(
WITH_ERRORS
,
argv
)))
if
(
virRun
(
NULL
,
argv
,
NULL
)
<
0
)
{
retval
=
errno
;
goto
error
;
}
if
(
action
==
REMOVE
&&
(
retval
=
iptablesAddRemoveChain
(
rules
,
action
)))
...
...
@@ -599,7 +503,7 @@ iptRulesReload(iptRules *rules)
orig
=
rule
->
argv
[
rule
->
flipflop
];
rule
->
argv
[
rule
->
flipflop
]
=
(
char
*
)
"--delete"
;
if
(
(
retval
=
iptablesSpawn
(
WITH_ERRORS
,
rule
->
argv
))
)
if
(
virRun
(
NULL
,
rule
->
argv
,
NULL
)
<
0
)
qemudLog
(
QEMUD_WARN
,
"Failed to remove iptables rule '%s' from chain '%s' in table '%s': %s"
,
rule
->
rule
,
rules
->
chain
,
rules
->
table
,
strerror
(
errno
));
...
...
@@ -612,9 +516,9 @@ iptRulesReload(iptRules *rules)
rules
->
chain
,
rules
->
table
,
strerror
(
retval
));
for
(
i
=
0
;
i
<
rules
->
nrules
;
i
++
)
if
(
(
retval
=
iptablesSpawn
(
WITH_ERRORS
,
rules
->
rules
[
i
].
argv
))
)
if
(
virRun
(
NULL
,
rules
->
rules
[
i
].
argv
,
NULL
)
<
0
)
qemudLog
(
QEMUD_WARN
,
"Failed to add iptables rule '%s' to chain '%s' in table '%s': %s"
,
rules
->
rules
[
i
].
rule
,
rules
->
chain
,
rules
->
table
,
strerror
(
retval
));
rules
->
rules
[
i
].
rule
,
rules
->
chain
,
rules
->
table
,
strerror
(
errno
));
}
/**
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录