Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
cb2e3e50
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看板
提交
cb2e3e50
编写于
5月 13, 2016
作者:
P
Peter Krempa
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
util: string: Introduce virStringEncodeBase64
Add a new helper that sanitizes error semantics of base64_encode_alloc.
上级
1d632c39
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
40 addition
and
31 deletion
+40
-31
src/conf/virsecretobj.c
src/conf/virsecretobj.c
+2
-5
src/libvirt_private.syms
src/libvirt_private.syms
+1
-0
src/qemu/qemu_agent.c
src/qemu/qemu_agent.c
+2
-4
src/storage/storage_backend_rbd.c
src/storage/storage_backend_rbd.c
+4
-13
src/util/virstring.c
src/util/virstring.c
+24
-0
src/util/virstring.h
src/util/virstring.h
+2
-0
tools/virsh-secret.c
tools/virsh-secret.c
+5
-9
未找到文件。
src/conf/virsecretobj.c
浏览文件 @
cb2e3e50
...
...
@@ -30,6 +30,7 @@
#include "virfile.h"
#include "virhash.h"
#include "virlog.h"
#include "virstring.h"
#include "base64.h"
#define VIR_FROM_THIS VIR_FROM_SECRET
...
...
@@ -730,12 +731,8 @@ virSecretObjSaveData(virSecretObjPtr secret)
if
(
!
secret
->
value
)
return
0
;
base64_encode_alloc
((
const
char
*
)
secret
->
value
,
secret
->
value_size
,
&
base64
);
if
(
base64
==
NULL
)
{
virReportOOMError
();
if
(
!
(
base64
=
virStringEncodeBase64
(
secret
->
value
,
secret
->
value_size
)))
goto
cleanup
;
}
if
(
virFileRewrite
(
secret
->
base64File
,
S_IRUSR
|
S_IWUSR
,
virSecretRewriteFile
,
base64
)
<
0
)
...
...
src/libvirt_private.syms
浏览文件 @
cb2e3e50
...
...
@@ -2303,6 +2303,7 @@ virSkipSpacesBackwards;
virStrcpy;
virStrdup;
virStringArrayHasString;
virStringEncodeBase64;
virStringFreeList;
virStringFreeListCount;
virStringGetFirstWithPrefix;
...
...
src/qemu/qemu_agent.c
浏览文件 @
cb2e3e50
...
...
@@ -2142,11 +2142,9 @@ qemuAgentSetUserPassword(qemuAgentPtr mon,
virJSONValuePtr
reply
=
NULL
;
char
*
password64
=
NULL
;
base64_encode_alloc
(
password
,
strlen
(
password
),
&
password64
);
if
(
!
password64
)
{
virReportOOMError
();
if
(
!
(
password64
=
virStringEncodeBase64
((
unsigned
char
*
)
password
,
strlen
(
password
))))
goto
cleanup
;
}
if
(
!
(
cmd
=
qemuAgentMakeCommand
(
"guest-set-user-password"
,
"b:crypted"
,
crypted
,
...
...
src/storage/storage_backend_rbd.c
浏览文件 @
cb2e3e50
...
...
@@ -59,7 +59,7 @@ virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr,
int
r
=
0
;
virStorageAuthDefPtr
authdef
=
source
->
auth
;
unsigned
char
*
secret_value
=
NULL
;
size_t
secret_value_size
;
size_t
secret_value_size
=
0
;
char
*
rados_key
=
NULL
;
virBuffer
mon_host
=
VIR_BUFFER_INITIALIZER
;
virSecretPtr
secret
=
NULL
;
...
...
@@ -129,15 +129,8 @@ virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr,
goto
cleanup
;
}
base64_encode_alloc
((
char
*
)
secret_value
,
secret_value_size
,
&
rados_key
);
memset
(
secret_value
,
0
,
secret_value_size
);
if
(
rados_key
==
NULL
)
{
virReportError
(
VIR_ERR_INTERNAL_ERROR
,
"%s"
,
_
(
"failed to decode the RADOS key"
));
if
(
!
(
rados_key
=
virStringEncodeBase64
(
secret_value
,
secret_value_size
)))
goto
cleanup
;
}
VIR_DEBUG
(
"Found cephx key: %s"
,
rados_key
);
if
(
rados_conf_set
(
ptr
->
cluster
,
"key"
,
rados_key
)
<
0
)
{
...
...
@@ -147,8 +140,6 @@ virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr,
goto
cleanup
;
}
memset
(
rados_key
,
0
,
strlen
(
rados_key
));
if
(
rados_conf_set
(
ptr
->
cluster
,
"auth_supported"
,
"cephx"
)
<
0
)
{
virReportError
(
VIR_ERR_INTERNAL_ERROR
,
_
(
"failed to set RADOS option: %s"
),
...
...
@@ -233,8 +224,8 @@ virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr,
ret
=
0
;
cleanup:
VIR_
FREE
(
secret_valu
e
);
VIR_
FREE
(
rados_key
);
VIR_
DISPOSE_N
(
secret_value
,
secret_value_siz
e
);
VIR_
DISPOSE_STRING
(
rados_key
);
virObjectUnref
(
secret
);
...
...
src/util/virstring.c
浏览文件 @
cb2e3e50
...
...
@@ -25,6 +25,7 @@
#include <stdio.h>
#include <regex.h>
#include "base64.h"
#include "c-ctype.h"
#include "virstring.h"
#include "viralloc.h"
...
...
@@ -1066,3 +1067,26 @@ virStringIsPrintable(const char *str)
return
true
;
}
/**
* virStringEncodeBase64:
* @buf: buffer of bytes to encode
* @buflen: number of bytes to encode
*
* Encodes @buf to base 64 and returns the resulting string. The caller is
* responsible for freeing the result.
*/
char
*
virStringEncodeBase64
(
const
uint8_t
*
buf
,
size_t
buflen
)
{
char
*
ret
;
base64_encode_alloc
((
const
char
*
)
buf
,
buflen
,
&
ret
);
if
(
!
ret
)
{
virReportOOMError
();
return
NULL
;
}
return
ret
;
}
src/util/virstring.h
浏览文件 @
cb2e3e50
...
...
@@ -277,4 +277,6 @@ void virStringStripControlChars(char *str);
bool
virStringIsPrintable
(
const
char
*
str
);
char
*
virStringEncodeBase64
(
const
uint8_t
*
buf
,
size_t
buflen
);
#endif
/* __VIR_STRING_H__ */
tools/virsh-secret.c
浏览文件 @
cb2e3e50
...
...
@@ -32,6 +32,7 @@
#include "viralloc.h"
#include "virfile.h"
#include "virutil.h"
#include "virstring.h"
#include "conf/secret_conf.h"
static
virSecretPtr
...
...
@@ -265,20 +266,15 @@ cmdSecretGetValue(vshControl *ctl, const vshCmd *cmd)
if
(
value
==
NULL
)
goto
cleanup
;
base64_encode_alloc
((
char
*
)
value
,
value_size
,
&
base64
);
memset
(
value
,
0
,
value_size
);
VIR_FREE
(
value
);
if
(
base64
==
NULL
)
{
vshError
(
ctl
,
"%s"
,
_
(
"Failed to allocate memory"
));
if
(
!
(
base64
=
virStringEncodeBase64
(
value
,
value_size
)))
goto
cleanup
;
}
vshPrint
(
ctl
,
"%s"
,
base64
);
memset
(
base64
,
0
,
strlen
(
base64
));
VIR_FREE
(
base64
);
ret
=
true
;
cleanup:
VIR_DISPOSE_N
(
value
,
value_size
);
VIR_DISPOSE_STRING
(
base64
);
virSecretFree
(
secret
);
return
ret
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录