!333 sync from upstream
From: @duguhaotian Reviewed-by: @jingwoo Signed-off-by: @jingwoo
This commit is contained in:
commit
58ce8cca01
@ -1,211 +0,0 @@
|
||||
From c0900d0bb68cb29484f670a67412447df316ff6e Mon Sep 17 00:00:00 2001
|
||||
From: zhangxiaoyu <zhangxiaoyu58@huawei.com>
|
||||
Date: Tue, 19 Apr 2022 18:33:16 +0800
|
||||
Subject: [PATCH 01/16] cleancode: http request
|
||||
|
||||
Signed-off-by: zhangxiaoyu <zhangxiaoyu58@huawei.com>
|
||||
---
|
||||
src/utils/http/http.c | 150 ++++++++++++++++++++++--------------------
|
||||
1 file changed, 77 insertions(+), 73 deletions(-)
|
||||
|
||||
diff --git a/src/utils/http/http.c b/src/utils/http/http.c
|
||||
index 2ed7fbe8..0b53cf1e 100644
|
||||
--- a/src/utils/http/http.c
|
||||
+++ b/src/utils/http/http.c
|
||||
@@ -95,38 +95,53 @@ void http_global_cleanup(void)
|
||||
curl_global_cleanup();
|
||||
}
|
||||
|
||||
+static int http_get_header_common(const unsigned int flag, const char *key, const char *value,
|
||||
+ struct curl_slist **chunk)
|
||||
+{
|
||||
+ int nret = 0;
|
||||
+ size_t len = 0;
|
||||
+ char *header = NULL;
|
||||
+
|
||||
+ if (flag == 0 || key == NULL || value == NULL) {
|
||||
+ return 0;
|
||||
+ }
|
||||
+
|
||||
+ // format key: value
|
||||
+ if (strlen(value) > (SIZE_MAX - strlen(key)) - 3) {
|
||||
+ ERROR("Invalid authorization option");
|
||||
+ return -1;
|
||||
+ }
|
||||
+
|
||||
+ // key + ": " + value + '\0'
|
||||
+ len = strlen(key) + strlen(value) + 3;
|
||||
+ header = util_common_calloc_s(len);
|
||||
+ if (header == NULL) {
|
||||
+ ERROR("Out of memory");
|
||||
+ return -1;
|
||||
+ }
|
||||
+
|
||||
+ nret = snprintf(header, len, "%s: %s", key, value);
|
||||
+ if (nret < 0 || (size_t)nret >= len) {
|
||||
+ ERROR("Failed to print string");
|
||||
+ } else {
|
||||
+ *chunk = curl_slist_append(*chunk, header);
|
||||
+ }
|
||||
+
|
||||
+ free(header);
|
||||
+ return nret == 0 ? 0 : -1;
|
||||
+}
|
||||
+
|
||||
struct curl_slist *http_get_chunk_header(const struct http_get_options *options)
|
||||
{
|
||||
int ret = 0;
|
||||
- int nret;
|
||||
- size_t len = 0;
|
||||
+ int i;
|
||||
struct curl_slist *chunk = NULL;
|
||||
- char *header = NULL;
|
||||
char **custom_headers = NULL;
|
||||
- int i = 0;
|
||||
|
||||
- if (options->with_header_auth && options->authorization) {
|
||||
- if (strlen(options->authorization) > (SIZE_MAX - strlen("Authorization: ")) - 1) {
|
||||
- ERROR("Invalid authorization option");
|
||||
- ret = -1;
|
||||
- goto out;
|
||||
- }
|
||||
- len = strlen(options->authorization) + strlen("Authorization: ") + 1;
|
||||
- header = util_common_calloc_s(len);
|
||||
- if (header == NULL) {
|
||||
- ERROR("Out of memory");
|
||||
- ret = -1;
|
||||
- goto out;
|
||||
- }
|
||||
- nret = snprintf(header, len, "Authorization: %s", options->authorization);
|
||||
- if (nret < 0 || (size_t)nret >= len) {
|
||||
- ERROR("Failed to print string");
|
||||
- ret = -1;
|
||||
- goto out;
|
||||
- }
|
||||
- chunk = curl_slist_append(chunk, header);
|
||||
- free(header);
|
||||
- header = NULL;
|
||||
+ ret = http_get_header_common(options->with_header_auth, "Authorization", options->authorization,
|
||||
+ &chunk);
|
||||
+ if (ret != 0) {
|
||||
+ goto out;
|
||||
}
|
||||
|
||||
if (options->with_header_json) {
|
||||
@@ -140,47 +155,47 @@ struct curl_slist *http_get_chunk_header(const struct http_get_options *options)
|
||||
chunk = curl_slist_append(chunk, custom_headers[i]);
|
||||
}
|
||||
|
||||
- if (options->with_header_accept && options->accepts) {
|
||||
- if (strlen(options->accepts) > (SIZE_MAX - strlen("Accept: ")) - 1) {
|
||||
- ERROR("Invalid accepts option");
|
||||
- ret = -1;
|
||||
- goto out;
|
||||
- }
|
||||
- len = strlen(options->accepts) + strlen("Accept: ") + 1;
|
||||
- header = util_common_calloc_s(len);
|
||||
- if (header == NULL) {
|
||||
- ERROR("Out of memory");
|
||||
- ret = -1;
|
||||
- goto out;
|
||||
- }
|
||||
- nret = snprintf(header, len, "Accept: %s", options->accepts);
|
||||
- if (nret < 0 || (size_t)nret >= len) {
|
||||
- ERROR("Failed to print string");
|
||||
- ret = -1;
|
||||
- goto out;
|
||||
- }
|
||||
- chunk = curl_slist_append(chunk, header);
|
||||
- free(header);
|
||||
- header = NULL;
|
||||
+ ret = http_get_header_common(options->with_header_accept, "Accept", options->accepts,
|
||||
+ &chunk);
|
||||
+ if (ret != 0) {
|
||||
+ goto out;
|
||||
}
|
||||
+
|
||||
out:
|
||||
- if (ret) {
|
||||
+ if (ret != 0) {
|
||||
curl_slist_free_all(chunk);
|
||||
chunk = NULL;
|
||||
}
|
||||
- free(header);
|
||||
|
||||
return chunk;
|
||||
}
|
||||
|
||||
-static int http_custom_options(CURL *curl_handle, const struct http_get_options *options)
|
||||
+static void http_custom_ssl_options(CURL *curl_handle, const struct http_get_options *options)
|
||||
{
|
||||
- int ret = 0;
|
||||
+ if (options->ssl_verify_peer) {
|
||||
+ curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 1L);
|
||||
+ } else {
|
||||
+ curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0L);
|
||||
+ }
|
||||
+ if (options->ssl_verify_host) {
|
||||
+ curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 2L);
|
||||
+ } else {
|
||||
+ curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 0L);
|
||||
+ }
|
||||
|
||||
- if (curl_handle == NULL || options == NULL) {
|
||||
- return -1;
|
||||
+ if (options->ca_file != NULL) {
|
||||
+ curl_easy_setopt(curl_handle, CURLOPT_CAINFO, options->ca_file);
|
||||
+ }
|
||||
+ if (options->cert_file != NULL) {
|
||||
+ curl_easy_setopt(curl_handle, CURLOPT_SSLCERT, options->cert_file);
|
||||
+ }
|
||||
+ if (options->key_file != NULL) {
|
||||
+ curl_easy_setopt(curl_handle, CURLOPT_SSLKEY, options->key_file);
|
||||
}
|
||||
+}
|
||||
|
||||
+static void http_custom_general_options(CURL *curl_handle, const struct http_get_options *options)
|
||||
+{
|
||||
if (options->timeout) {
|
||||
/* complete connection within 30 seconds */
|
||||
curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT, 30L);
|
||||
@@ -222,29 +237,18 @@ static int http_custom_options(CURL *curl_handle, const struct http_get_options
|
||||
if (options->debug) {
|
||||
curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1L);
|
||||
}
|
||||
+}
|
||||
|
||||
- if (options->ssl_verify_peer) {
|
||||
- curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 1L);
|
||||
- } else {
|
||||
- curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0L);
|
||||
- }
|
||||
- if (options->ssl_verify_host) {
|
||||
- curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 2L);
|
||||
- } else {
|
||||
- curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 0L);
|
||||
+static int http_custom_options(CURL *curl_handle, const struct http_get_options *options)
|
||||
+{
|
||||
+ if (curl_handle == NULL || options == NULL) {
|
||||
+ return -1;
|
||||
}
|
||||
|
||||
- if (options->ca_file != NULL) {
|
||||
- curl_easy_setopt(curl_handle, CURLOPT_CAINFO, options->ca_file);
|
||||
- }
|
||||
- if (options->cert_file != NULL) {
|
||||
- curl_easy_setopt(curl_handle, CURLOPT_SSLCERT, options->cert_file);
|
||||
- }
|
||||
- if (options->key_file != NULL) {
|
||||
- curl_easy_setopt(curl_handle, CURLOPT_SSLKEY, options->key_file);
|
||||
- }
|
||||
+ http_custom_general_options(curl_handle, options);
|
||||
+ http_custom_ssl_options(curl_handle, options);
|
||||
|
||||
- return ret;
|
||||
+ return 0;
|
||||
}
|
||||
|
||||
static void close_file(FILE *pagefile)
|
||||
--
|
||||
2.20.1
|
||||
|
||||
@ -1,235 +0,0 @@
|
||||
From b58453982016f9a2f707b51ad54f12583aa21929 Mon Sep 17 00:00:00 2001
|
||||
From: wujing <wujing50@huawei.com>
|
||||
Date: Wed, 20 Apr 2022 10:52:30 +0800
|
||||
Subject: [PATCH 02/16] refactor mount parse in spec module
|
||||
|
||||
Signed-off-by: wujing <wujing50@huawei.com>
|
||||
---
|
||||
src/daemon/modules/spec/specs_mount.c | 160 +++++++++++++++++---------
|
||||
1 file changed, 106 insertions(+), 54 deletions(-)
|
||||
|
||||
diff --git a/src/daemon/modules/spec/specs_mount.c b/src/daemon/modules/spec/specs_mount.c
|
||||
index 5644b21e..c89f077f 100644
|
||||
--- a/src/daemon/modules/spec/specs_mount.c
|
||||
+++ b/src/daemon/modules/spec/specs_mount.c
|
||||
@@ -580,7 +580,7 @@ out:
|
||||
static int append_tmpfs_option_size(defs_mount *m, size_t size)
|
||||
{
|
||||
int nret = 0;
|
||||
- char kvbuf[MOUNT_PROPERTIES_SIZE] = {0};
|
||||
+ char kvbuf[MOUNT_PROPERTIES_SIZE] = { 0 };
|
||||
|
||||
if (size == 0) {
|
||||
return 0;
|
||||
@@ -604,7 +604,7 @@ static int append_tmpfs_option_size(defs_mount *m, size_t size)
|
||||
static int append_tmpfs_option_mode(defs_mount *m, uint32_t mode)
|
||||
{
|
||||
int nret = 0;
|
||||
- char kvbuf[MOUNT_PROPERTIES_SIZE] = {0};
|
||||
+ char kvbuf[MOUNT_PROPERTIES_SIZE] = { 0 };
|
||||
|
||||
if (mode == 0) {
|
||||
return 0;
|
||||
@@ -625,19 +625,8 @@ static int append_tmpfs_option_mode(defs_mount *m, uint32_t mode)
|
||||
return 0;
|
||||
}
|
||||
|
||||
-static defs_mount *parse_mount(mount_spec *spec)
|
||||
+static int parse_basic_mount_spec_fileds(const mount_spec *spec, defs_mount *m)
|
||||
{
|
||||
- int ret = 0;
|
||||
- defs_mount *m = NULL;
|
||||
- bool has_pro = false;
|
||||
- bool has_sel = false;
|
||||
-
|
||||
- m = util_common_calloc_s(sizeof(defs_mount));
|
||||
- if (m == NULL) {
|
||||
- ERROR("Out of memory");
|
||||
- return NULL;
|
||||
- }
|
||||
-
|
||||
m->type = util_strdup_s(spec->type);
|
||||
if (strcmp(m->type, MOUNT_TYPE_TMPFS) == 0) {
|
||||
m->source = util_strdup_s("tmpfs");
|
||||
@@ -652,58 +641,122 @@ static defs_mount *parse_mount(mount_spec *spec)
|
||||
if (spec->readonly) {
|
||||
if (util_array_append(&m->options, "ro")) {
|
||||
ERROR("append ro mode to array failed");
|
||||
- ret = -1;
|
||||
- goto out;
|
||||
+ return -1;
|
||||
}
|
||||
m->options_len++;
|
||||
}
|
||||
|
||||
- if (spec->bind_options != NULL) {
|
||||
- if (spec->bind_options->propagation != NULL) {
|
||||
- if (util_array_append(&m->options, spec->bind_options->propagation)) {
|
||||
- ERROR("append propagation to array failed");
|
||||
- ret = -1;
|
||||
- goto out;
|
||||
- }
|
||||
- m->options_len++;
|
||||
- has_pro = true;
|
||||
- }
|
||||
- if (spec->bind_options->selinux_opts != NULL) {
|
||||
- if (util_array_append(&m->options, spec->bind_options->selinux_opts)) {
|
||||
- ERROR("append selinux opts to array failed");
|
||||
- ret = -1;
|
||||
- goto out;
|
||||
- }
|
||||
- m->options_len++;
|
||||
- has_sel = true;
|
||||
- }
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+static int append_spec_bind_mount_options(const mount_spec *spec, defs_mount *m, bool *has_pro, bool *has_sel)
|
||||
+{
|
||||
+ if (spec->bind_options == NULL) {
|
||||
+ return 0;
|
||||
}
|
||||
|
||||
- if (spec->volume_options != NULL && spec->volume_options->no_copy) {
|
||||
- if (util_array_append(&m->options, "nocopy")) {
|
||||
- ERROR("append nocopy to array failed");
|
||||
- ret = -1;
|
||||
- goto out;
|
||||
+ if (spec->bind_options->propagation != NULL) {
|
||||
+ if (util_array_append(&m->options, spec->bind_options->propagation)) {
|
||||
+ ERROR("append propagation to array failed");
|
||||
+ return -1;
|
||||
}
|
||||
m->options_len++;
|
||||
+ *has_pro = true;
|
||||
}
|
||||
-
|
||||
- if (strcmp(m->type, MOUNT_TYPE_TMPFS) == 0 && spec->tmpfs_options != NULL) {
|
||||
- if (append_tmpfs_option_size(m, (size_t) spec->tmpfs_options->size_bytes) != 0) {
|
||||
- ERROR("append tmpfs option size failed");
|
||||
- ret = -1;
|
||||
- goto out;
|
||||
+ if (spec->bind_options->selinux_opts != NULL) {
|
||||
+ if (util_array_append(&m->options, spec->bind_options->selinux_opts)) {
|
||||
+ ERROR("append selinux opts to array failed");
|
||||
+ return -1;
|
||||
}
|
||||
+ m->options_len++;
|
||||
+ *has_sel = true;
|
||||
+ }
|
||||
|
||||
- if (append_tmpfs_option_mode(m, spec->tmpfs_options->mode) != 0) {
|
||||
- ERROR("append tmpfs option mode failed");
|
||||
- ret = -1;
|
||||
- goto out;
|
||||
- }
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+static int append_spec_volume_options(const mount_spec *spec, defs_mount *m)
|
||||
+{
|
||||
+ if (spec->volume_options == NULL || !spec->volume_options->no_copy) {
|
||||
+ return 0;
|
||||
+ }
|
||||
+
|
||||
+ if (util_array_append(&m->options, "nocopy")) {
|
||||
+ ERROR("append nocopy to array failed");
|
||||
+ return -1;
|
||||
+ }
|
||||
+ m->options_len++;
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+static int append_spec_tmpfs_options(const mount_spec *spec, defs_mount *m)
|
||||
+{
|
||||
+ if (strcmp(m->type, MOUNT_TYPE_TMPFS) != 0 || spec->tmpfs_options == NULL) {
|
||||
+ return 0;
|
||||
+ }
|
||||
+
|
||||
+ if (append_tmpfs_option_size(m, (size_t)spec->tmpfs_options->size_bytes) != 0) {
|
||||
+ ERROR("append tmpfs option size failed");
|
||||
+ return -1;
|
||||
+ }
|
||||
+
|
||||
+ if (append_tmpfs_option_mode(m, spec->tmpfs_options->mode) != 0) {
|
||||
+ ERROR("append tmpfs option mode failed");
|
||||
+ return -1;
|
||||
+ }
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+static int append_spec_mount_options(const mount_spec *spec, defs_mount *m, bool *has_pro, bool *has_sel)
|
||||
+{
|
||||
+ if (append_spec_bind_mount_options(spec, m, has_pro, has_sel) != 0) {
|
||||
+ ERROR("Failed to append bind options in v2_spec");
|
||||
+ return -1;
|
||||
+ }
|
||||
+
|
||||
+ if (append_spec_volume_options(spec, m) != 0) {
|
||||
+ ERROR("Failed to append volume options in v2_spec");
|
||||
+ return -1;
|
||||
+ }
|
||||
+
|
||||
+ if (append_spec_tmpfs_options(spec, m) != 0) {
|
||||
+ ERROR("Failed to append tmpfs options in v2_spec");
|
||||
+ return -1;
|
||||
+ }
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+static defs_mount *parse_mount(const mount_spec *spec)
|
||||
+{
|
||||
+ int ret = 0;
|
||||
+ defs_mount *m = NULL;
|
||||
+ bool has_pro = false;
|
||||
+ bool has_sel = false;
|
||||
+
|
||||
+ m = util_common_calloc_s(sizeof(defs_mount));
|
||||
+ if (m == NULL) {
|
||||
+ ERROR("Out of memory");
|
||||
+ return NULL;
|
||||
+ }
|
||||
+
|
||||
+ ret = parse_basic_mount_spec_fileds(spec, m);
|
||||
+ if (ret != 0) {
|
||||
+ ERROR("Failed to parse basic mount fileds in v2_spec");
|
||||
+ goto out;
|
||||
+ }
|
||||
+
|
||||
+ ret = append_spec_mount_options(spec, m, &has_pro, &has_sel);
|
||||
+ if (ret != 0) {
|
||||
+ ERROR("Failed to append spec mount options");
|
||||
+ goto out;
|
||||
}
|
||||
|
||||
ret = append_default_mount_options(m, true, has_pro, has_sel);
|
||||
if (ret != 0) {
|
||||
+ ERROR("Failed to append default mount options");
|
||||
goto out;
|
||||
}
|
||||
|
||||
@@ -2857,8 +2910,7 @@ static void add_mount(defs_mount **merged_mounts, size_t *merged_mounts_len, def
|
||||
*merged_mounts_len += 1;
|
||||
}
|
||||
|
||||
-static int add_embedded_layers(container_config *container_spec, defs_mount **merged_mounts,
|
||||
- size_t *merged_mounts_len)
|
||||
+static int add_embedded_layers(container_config *container_spec, defs_mount **merged_mounts, size_t *merged_mounts_len)
|
||||
{
|
||||
int ret = 0;
|
||||
size_t i = 0;
|
||||
@@ -2976,7 +3028,7 @@ out:
|
||||
|
||||
static char *get_valid_tmpfs_dst_path(char *tmpfs)
|
||||
{
|
||||
- char dstpath[PATH_MAX] = {0};
|
||||
+ char dstpath[PATH_MAX] = { 0 };
|
||||
|
||||
if (tmpfs == NULL) {
|
||||
return NULL;
|
||||
--
|
||||
2.20.1
|
||||
|
||||
@ -1,30 +0,0 @@
|
||||
From e0c13b23ddee161a6196ca2e0c970704e4bbef0e Mon Sep 17 00:00:00 2001
|
||||
From: WangFengTu <wangfengtu@huawei.com>
|
||||
Date: Sun, 24 Apr 2022 14:18:26 +0800
|
||||
Subject: [PATCH 03/16] support isula wait even if it's not oci image
|
||||
|
||||
Signed-off-by: WangFengTu <wangfengtu@huawei.com>
|
||||
---
|
||||
src/cmd/isula/main.c | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/src/cmd/isula/main.c b/src/cmd/isula/main.c
|
||||
index 0e5b845c..2deb862c 100644
|
||||
--- a/src/cmd/isula/main.c
|
||||
+++ b/src/cmd/isula/main.c
|
||||
@@ -134,11 +134,11 @@ struct command g_commands[] = {
|
||||
"rmi", false, cmd_rmi_main, g_cmd_rmi_desc, NULL, &g_cmd_rmi_args
|
||||
},
|
||||
#endif
|
||||
-#ifdef ENABLE_OCI_IMAGE
|
||||
{
|
||||
// `wait` sub-command
|
||||
"wait", false, cmd_wait_main, g_cmd_wait_desc, NULL, &g_cmd_wait_args
|
||||
},
|
||||
+#ifdef ENABLE_OCI_IMAGE
|
||||
{
|
||||
// `logs` sub-command
|
||||
"logs", false, cmd_logs_main, g_cmd_logs_desc, NULL, &g_cmd_logs_args
|
||||
--
|
||||
2.20.1
|
||||
|
||||
@ -1,267 +0,0 @@
|
||||
From 0f05484cceb58117f165bcc402156194289ea9c3 Mon Sep 17 00:00:00 2001
|
||||
From: chengzrz <czrzrichard@gmail.com>
|
||||
Date: Thu, 28 Apr 2022 19:11:46 +0800
|
||||
Subject: [PATCH 04/16] add isula import restful mode
|
||||
|
||||
Signed-off-by: chengzrz <czrzrichard@gmail.com>
|
||||
---
|
||||
src/api/services/images/rest/image.rest.h | 3 +
|
||||
src/client/connect/rest/rest_images_client.c | 107 ++++++++++++++++++
|
||||
.../entry/connect/rest/rest_images_service.c | 89 +++++++++++++++
|
||||
3 files changed, 199 insertions(+)
|
||||
|
||||
diff --git a/src/api/services/images/rest/image.rest.h b/src/api/services/images/rest/image.rest.h
|
||||
index 6ebdc109..a61a285f 100644
|
||||
--- a/src/api/services/images/rest/image.rest.h
|
||||
+++ b/src/api/services/images/rest/image.rest.h
|
||||
@@ -31,6 +31,8 @@
|
||||
#include "isula_libutils/image_logout_response.h"
|
||||
#include "isula_libutils/image_tag_image_request.h"
|
||||
#include "isula_libutils/image_tag_image_response.h"
|
||||
+#include "isula_libutils/image_import_request.h"
|
||||
+#include "isula_libutils/image_import_response.h"
|
||||
|
||||
#ifndef RestHttpHead
|
||||
#define RestHttpHead "http://localhost"
|
||||
@@ -44,6 +46,7 @@
|
||||
#define ImagesServiceLogin "/ImagesService/Login"
|
||||
#define ImagesServiceLogout "/ImagesService/Logout"
|
||||
#define ImagesServiceTag "/ImagesService/Tag"
|
||||
+#define ImagesServiceImport "/ImagesService/Import"
|
||||
|
||||
#endif
|
||||
|
||||
diff --git a/src/client/connect/rest/rest_images_client.c b/src/client/connect/rest/rest_images_client.c
|
||||
index ae754f76..3deeeead 100644
|
||||
--- a/src/client/connect/rest/rest_images_client.c
|
||||
+++ b/src/client/connect/rest/rest_images_client.c
|
||||
@@ -858,6 +858,112 @@ out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
+/* image import request to rest */
|
||||
+static int image_import_request_to_rest(const struct isula_import_request *request, char **body, size_t *body_len)
|
||||
+{
|
||||
+ image_import_request *crequest = NULL;
|
||||
+ parser_error err = NULL;
|
||||
+ int ret = 0;
|
||||
+
|
||||
+ crequest = util_common_calloc_s(sizeof(image_import_request));
|
||||
+ if (crequest == NULL) {
|
||||
+ ERROR("Out of memory");
|
||||
+ return -1;
|
||||
+ }
|
||||
+ crequest->file = util_strdup_s(request->file);
|
||||
+ crequest->tag = util_strdup_s(request->tag);
|
||||
+
|
||||
+ *body = image_import_request_generate_json(crequest, NULL, &err);
|
||||
+ if (*body == NULL) {
|
||||
+ ERROR("Failed to generate image import request json:%s", err);
|
||||
+ ret = -1;
|
||||
+ goto out;
|
||||
+ }
|
||||
+ *body_len = strlen(*body) + 1;
|
||||
+
|
||||
+out:
|
||||
+ free(err);
|
||||
+ free_image_import_request(crequest);
|
||||
+
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
+/* unpack image import response */
|
||||
+static int unpack_image_import_response(const struct parsed_http_message *message, void *arg)
|
||||
+{
|
||||
+ struct isula_import_response *c_import_response = (struct isula_import_response *)arg;
|
||||
+ image_import_response *import_response = NULL;
|
||||
+ parser_error err = NULL;
|
||||
+ int ret = 0;
|
||||
+
|
||||
+ ret = check_status_code(message->status_code);
|
||||
+ if (ret != 0) {
|
||||
+ ERROR("Tag image check status code failed.\n");
|
||||
+ goto out;
|
||||
+ }
|
||||
+
|
||||
+ import_response = image_import_response_parse_data(message->body, NULL, &err);
|
||||
+ if (import_response == NULL) {
|
||||
+ ERROR("Invalid import image response:%s", err);
|
||||
+ ret = -1;
|
||||
+ goto out;
|
||||
+ }
|
||||
+
|
||||
+ c_import_response->server_errono = import_response->cc;
|
||||
+ c_import_response->errmsg = util_strdup_s(import_response->errmsg);
|
||||
+ c_import_response->id = util_strdup_s(import_response->id);
|
||||
+
|
||||
+ ret = (import_response->cc == ISULAD_SUCCESS) ? 0 : -1;
|
||||
+ if (message->status_code == RESTFUL_RES_SERVERR) {
|
||||
+ ret = -1;
|
||||
+ }
|
||||
+
|
||||
+out:
|
||||
+ free(err);
|
||||
+ free_image_import_response(import_response);
|
||||
+
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
+/* rest image import */
|
||||
+static int rest_image_import(const struct isula_import_request *request, struct isula_import_response *response,
|
||||
+ void *arg)
|
||||
+{
|
||||
+
|
||||
+ client_connect_config_t *connect_config = (client_connect_config_t *)arg;
|
||||
+ const char *socketname = (const char *)(connect_config->socket);
|
||||
+ char *body = NULL;
|
||||
+ Buffer *output = NULL;
|
||||
+ int ret = 0;
|
||||
+ size_t len = 0;
|
||||
+
|
||||
+ ret = image_import_request_to_rest(request, &body, &len);
|
||||
+ if (ret != 0) {
|
||||
+ goto out;
|
||||
+ }
|
||||
+
|
||||
+ ret = rest_send_requst(socketname, RestHttpHead ImagesServiceImport, body, len, &output);
|
||||
+ if (ret != 0) {
|
||||
+ ERROR("Send import request failed.");
|
||||
+ response->errmsg = util_strdup_s(errno_to_error_message(ISULAD_ERR_CONNECT));
|
||||
+ response->cc = ISULAD_ERR_EXEC;
|
||||
+ goto out;
|
||||
+ }
|
||||
+
|
||||
+ ret = get_response(output, unpack_image_import_response, (void *)response);
|
||||
+ if (ret != 0) {
|
||||
+ ERROR("Get import response failed.");
|
||||
+ goto out;
|
||||
+ }
|
||||
+
|
||||
+out:
|
||||
+ buffer_free(output);
|
||||
+ put_body(body);
|
||||
+
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
+
|
||||
/* rest images client ops init */
|
||||
int rest_images_client_ops_init(isula_connect_ops *ops)
|
||||
{
|
||||
@@ -873,6 +979,7 @@ int rest_images_client_ops_init(isula_connect_ops *ops)
|
||||
ops->image.login = &rest_image_login;
|
||||
ops->image.logout = &rest_image_logout;
|
||||
ops->image.tag = &rest_image_tag;
|
||||
+ ops->image.import = &rest_image_import;
|
||||
|
||||
return 0;
|
||||
}
|
||||
diff --git a/src/daemon/entry/connect/rest/rest_images_service.c b/src/daemon/entry/connect/rest/rest_images_service.c
|
||||
index 39a3bd6c..7107d255 100644
|
||||
--- a/src/daemon/entry/connect/rest/rest_images_service.c
|
||||
+++ b/src/daemon/entry/connect/rest/rest_images_service.c
|
||||
@@ -797,6 +797,90 @@ out:
|
||||
free_image_tag_image_response(cresponse);
|
||||
}
|
||||
|
||||
+/* image import request from rest */
|
||||
+static int image_import_request_from_rest(evhtp_request_t *req, image_import_request **crequest)
|
||||
+{
|
||||
+ int ret = 0;
|
||||
+ size_t body_len;
|
||||
+ char *body = NULL;
|
||||
+ parser_error err = NULL;
|
||||
+
|
||||
+ if (get_body(req, &body_len, &body) != 0) {
|
||||
+ ERROR("Failed to get body");
|
||||
+ return -1;
|
||||
+ }
|
||||
+
|
||||
+ *crequest = image_import_request_parse_data(body, NULL, &err);
|
||||
+ if (*crequest == NULL) {
|
||||
+ ERROR("Invalid import request body:%s", err);
|
||||
+ ret = -1;
|
||||
+ goto out;
|
||||
+ }
|
||||
+
|
||||
+out:
|
||||
+ put_body(body);
|
||||
+ free(err);
|
||||
+
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
+/* evhtp send image import repsponse */
|
||||
+static void evhtp_send_image_import_repsponse(evhtp_request_t *req, image_import_response *response, int rescode)
|
||||
+{
|
||||
+ parser_error err = NULL;
|
||||
+ char *response_data = NULL;
|
||||
+
|
||||
+ response_data = image_import_response_generate_json(response, NULL, &err);
|
||||
+ if (response_data != NULL) {
|
||||
+ evhtp_send_response(req, response_data, rescode);
|
||||
+ goto out;
|
||||
+ }
|
||||
+
|
||||
+ ERROR("Import: failed to generate request json:%s", err);
|
||||
+ evhtp_send_reply(req, RESTFUL_RES_ERROR);
|
||||
+
|
||||
+out:
|
||||
+ free(response_data);
|
||||
+ free(err);
|
||||
+}
|
||||
+
|
||||
+/* rest image import cb */
|
||||
+static void rest_image_import_cb(evhtp_request_t *req, void *arg)
|
||||
+{
|
||||
+ int tret;
|
||||
+ service_executor_t *cb = NULL;
|
||||
+ image_import_request *crequest = NULL;
|
||||
+ image_import_response *cresponse = NULL;
|
||||
+
|
||||
+ // only deal with POST request
|
||||
+ if (evhtp_request_get_method(req) != htp_method_POST) {
|
||||
+ evhtp_send_reply(req, RESTFUL_RES_NOTIMPL);
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ cb = get_service_executor();
|
||||
+ if (cb == NULL || cb->image.import == NULL) {
|
||||
+ ERROR("Unimplemented import callback");
|
||||
+ evhtp_send_reply(req, RESTFUL_RES_NOTIMPL);
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ tret = image_import_request_from_rest(req, &crequest);
|
||||
+ if (tret < 0) {
|
||||
+ ERROR("Bad request");
|
||||
+ evhtp_send_reply(req, RESTFUL_RES_SERVERR);
|
||||
+ goto out;
|
||||
+ }
|
||||
+
|
||||
+ (void)cb->image.import(crequest, &cresponse);
|
||||
+ evhtp_send_image_import_repsponse(req, cresponse, RESTFUL_RES_OK);
|
||||
+
|
||||
+out:
|
||||
+ free_image_import_request(crequest);
|
||||
+ free_image_import_response(cresponse);
|
||||
+}
|
||||
+
|
||||
+
|
||||
/* rest register images handler */
|
||||
int rest_register_images_handler(evhtp_t *htp)
|
||||
{
|
||||
@@ -840,5 +924,10 @@ int rest_register_images_handler(evhtp_t *htp)
|
||||
return -1;
|
||||
}
|
||||
|
||||
+ if (evhtp_set_cb(htp, ImagesServiceImport, rest_image_import_cb, NULL) == NULL) {
|
||||
+ ERROR("Failed to register image logout callback");
|
||||
+ return -1;
|
||||
+ }
|
||||
+
|
||||
return 0;
|
||||
}
|
||||
--
|
||||
2.20.1
|
||||
|
||||
@ -1,658 +0,0 @@
|
||||
From 1d768559f42375eb3bbb3ad0de52a6b49535e40c Mon Sep 17 00:00:00 2001
|
||||
From: chegJH <hejunjie10@huawei.com>
|
||||
Date: Thu, 7 Apr 2022 17:33:06 +0800
|
||||
Subject: [PATCH 05/16] Adapt to bionic libc, parser for passwd and group
|
||||
object
|
||||
|
||||
Signed-off-by: chegJH <hejunjie10@huawei.com>
|
||||
---
|
||||
.../modules/image/image_rootfs_handler.c | 25 ++
|
||||
src/utils/cutils/utils_pwgr.c | 317 ++++++++++++++++++
|
||||
src/utils/cutils/utils_pwgr.h | 33 ++
|
||||
test/cutils/CMakeLists.txt | 1 +
|
||||
test/cutils/utils_pwgr/CMakeLists.txt | 29 ++
|
||||
test/cutils/utils_pwgr/group_sample | 8 +
|
||||
test/cutils/utils_pwgr/passwd_sample | 11 +
|
||||
test/cutils/utils_pwgr/utils_pwgr_ut.cc | 101 ++++++
|
||||
8 files changed, 525 insertions(+)
|
||||
create mode 100644 src/utils/cutils/utils_pwgr.c
|
||||
create mode 100644 src/utils/cutils/utils_pwgr.h
|
||||
create mode 100644 test/cutils/utils_pwgr/CMakeLists.txt
|
||||
create mode 100644 test/cutils/utils_pwgr/group_sample
|
||||
create mode 100644 test/cutils/utils_pwgr/passwd_sample
|
||||
create mode 100644 test/cutils/utils_pwgr/utils_pwgr_ut.cc
|
||||
|
||||
diff --git a/src/daemon/modules/image/image_rootfs_handler.c b/src/daemon/modules/image/image_rootfs_handler.c
|
||||
index f7bc9bc9..960d52c7 100644
|
||||
--- a/src/daemon/modules/image/image_rootfs_handler.c
|
||||
+++ b/src/daemon/modules/image/image_rootfs_handler.c
|
||||
@@ -33,6 +33,7 @@
|
||||
#include "path.h"
|
||||
#include "utils_convert.h"
|
||||
#include "utils_file.h"
|
||||
+#include "utils_pwgr.h"
|
||||
|
||||
#define MINUID 0
|
||||
#define MAXUID (((1LL << 31) - 1))
|
||||
@@ -88,7 +89,11 @@ static int proc_by_fpasswd(FILE *f_passwd, const char *user, defs_process_user *
|
||||
struct passwd *pwbufp = NULL;
|
||||
|
||||
if (f_passwd != NULL) {
|
||||
+#ifdef __ANDROID__
|
||||
+ errval = util_getpwent_r(f_passwd, &pw, buf, sizeof(buf), &pwbufp);
|
||||
+#else
|
||||
errval = fgetpwent_r(f_passwd, &pw, buf, sizeof(buf), &pwbufp);
|
||||
+#endif
|
||||
|
||||
while (errval == 0 && pwbufp != NULL) {
|
||||
userfound = b_user_found(user, pwbufp);
|
||||
@@ -102,7 +107,11 @@ static int proc_by_fpasswd(FILE *f_passwd, const char *user, defs_process_user *
|
||||
*matched_username = util_strdup_s(pwbufp->pw_name);
|
||||
break;
|
||||
}
|
||||
+#ifdef __ANDROID__
|
||||
+ errval = util_getpwent_r(f_passwd, &pw, buf, sizeof(buf), &pwbufp);
|
||||
+#else
|
||||
errval = fgetpwent_r(f_passwd, &pw, buf, sizeof(buf), &pwbufp);
|
||||
+#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,14 +221,22 @@ static int do_proc_by_froup(FILE *f_group, const char *group, defs_process_user
|
||||
return 0;
|
||||
}
|
||||
|
||||
+#ifdef __ANDROID__
|
||||
+ errval = util_getgrent_r(f_group, &grp, buf, sizeof(buf), &gbufp);
|
||||
+#else
|
||||
errval = fgetgrent_r(f_group, &grp, buf, sizeof(buf), &gbufp);
|
||||
+#endif
|
||||
while (errval == 0 && gbufp != NULL) {
|
||||
// Treat numeric group as valid GID
|
||||
if (group == NULL) {
|
||||
if (search_group_list(gbufp, matched_username, puser) != 0) {
|
||||
return -1;
|
||||
}
|
||||
+#ifdef __ANDROID__
|
||||
+ errval = util_getgrent_r(f_group, &grp, buf, sizeof(buf), &gbufp);
|
||||
+#else
|
||||
errval = fgetgrent_r(f_group, &grp, buf, sizeof(buf), &gbufp);
|
||||
+#endif
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -229,7 +246,11 @@ static int do_proc_by_froup(FILE *f_group, const char *group, defs_process_user
|
||||
puser->gid = gbufp->gr_gid;
|
||||
*groupcnt = 1;
|
||||
}
|
||||
+#ifdef __ANDROID__
|
||||
+ errval = util_getgrent_r(f_group, &grp, buf, sizeof(buf), &gbufp);
|
||||
+#else
|
||||
errval = fgetgrent_r(f_group, &grp, buf, sizeof(buf), &gbufp);
|
||||
+#endif
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -363,7 +384,11 @@ static int get_additional_groups(char **additional_groups, size_t additional_gro
|
||||
struct group *gbufp = NULL;
|
||||
struct group *groups = NULL;
|
||||
|
||||
+#ifdef __ANDROID__
|
||||
+ while (f_group != NULL && util_getgrent_r(f_group, &grp, buf, sizeof(buf), &gbufp) == 0) {
|
||||
+#else
|
||||
while (f_group != NULL && fgetgrent_r(f_group, &grp, buf, sizeof(buf), &gbufp) == 0) {
|
||||
+#endif
|
||||
for (i = 0; i < additional_groups_len; i++) {
|
||||
if (!group_matched(additional_groups[i], gbufp)) {
|
||||
continue;
|
||||
diff --git a/src/utils/cutils/utils_pwgr.c b/src/utils/cutils/utils_pwgr.c
|
||||
new file mode 100644
|
||||
index 00000000..f4588268
|
||||
--- /dev/null
|
||||
+++ b/src/utils/cutils/utils_pwgr.c
|
||||
@@ -0,0 +1,317 @@
|
||||
+/******************************************************************************
|
||||
+ * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved.
|
||||
+ * iSulad licensed under the Mulan PSL v2.
|
||||
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
+ * You may obtain a copy of Mulan PSL v2 at:
|
||||
+ * http://license.coscl.org.cn/MulanPSL2
|
||||
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
||||
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
||||
+ * PURPOSE.
|
||||
+ * See the Mulan PSL v2 for more details.
|
||||
+ * Author: hejunjie
|
||||
+ * Create: 2022-04-08
|
||||
+ * Description: Provide line parser for android
|
||||
+ *******************************************************************************/
|
||||
+
|
||||
+#define _GNU_SOURCE
|
||||
+#include "utils_pwgr.h"
|
||||
+
|
||||
+#include <unistd.h>
|
||||
+#include <errno.h>
|
||||
+#include <stdlib.h>
|
||||
+#include <stdio_ext.h>
|
||||
+
|
||||
+#include "isula_libutils/log.h"
|
||||
+#include "utils_string.h"
|
||||
+#include "utils_convert.h"
|
||||
+#include "utils_file.h"
|
||||
+#include "utils.h"
|
||||
+
|
||||
+static int hold_int(const char delim, bool required, char **src, unsigned int *dst)
|
||||
+{
|
||||
+ long long res = 0;
|
||||
+ char *walker = *src;
|
||||
+ char *err_str = NULL;
|
||||
+
|
||||
+ if (**src == '\0') {
|
||||
+ ERROR("Empty subject on given entrie is not allowed.");
|
||||
+ return -1;
|
||||
+ }
|
||||
+
|
||||
+ while (*walker != delim) {
|
||||
+ if (*walker == '\0') {
|
||||
+ break;
|
||||
+ }
|
||||
+ ++walker;
|
||||
+ }
|
||||
+
|
||||
+ if (*walker == **src) {
|
||||
+ if (required) { // deafult 0 while required full content but integer part is missing
|
||||
+ *dst = 0;
|
||||
+ *src = walker + 1;
|
||||
+ return 0;
|
||||
+ }
|
||||
+ ERROR("Integer part is missing.");
|
||||
+ ++(*src);
|
||||
+ return -1;
|
||||
+ }
|
||||
+
|
||||
+ res = strtoll(*src, &err_str, 0);
|
||||
+ if (errno == ERANGE) {
|
||||
+ ERROR("Parse int from string failed.");
|
||||
+ return -1;
|
||||
+ }
|
||||
+ if (res < 0) {
|
||||
+ ERROR("Gid uid shall not be negative.");
|
||||
+ return -1;
|
||||
+ }
|
||||
+
|
||||
+ if (sizeof(void *) > 4 && res > UINT_MAX) { // make sure 64-bit platform behave same as 32-bit
|
||||
+ res = UINT_MAX;
|
||||
+ }
|
||||
+ res = res & UINT_MAX;
|
||||
+ *dst = (uint32_t)res;
|
||||
+ *src = err_str + 1; // update src to next valid context in line.
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+static int hold_string(const char delim, char **src, char **dst)
|
||||
+{
|
||||
+ if (**src == delim) { // if src point to deliminator, content parsing is skiped.
|
||||
+ *dst = "";
|
||||
+ *src = *src + 1;
|
||||
+ return 0;
|
||||
+ }
|
||||
+
|
||||
+ if (**src == '\0') {
|
||||
+ return 0;
|
||||
+ }
|
||||
+
|
||||
+ for (*dst = *src; **src != delim; ++(*src)) {
|
||||
+ if (**src == '\0') {
|
||||
+ break;
|
||||
+ }
|
||||
+ }
|
||||
+ if (**src == delim) {
|
||||
+ **src = '\0';
|
||||
+ ++(*src);
|
||||
+ }
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+static int parse_line_pw(const char delim, char *line, struct passwd *result)
|
||||
+{
|
||||
+ int ret = 0;
|
||||
+ bool required = false;
|
||||
+
|
||||
+ ret = hold_string(delim, &line, &result->pw_name);
|
||||
+ if (ret != 0) {
|
||||
+ ERROR("Parse name error.");
|
||||
+ return ret;
|
||||
+ }
|
||||
+
|
||||
+ required = (result->pw_name[0] == '+' || result->pw_name[0] == '-') ? true : false;
|
||||
+
|
||||
+ ret = hold_string(delim, &line, &result->pw_passwd);
|
||||
+ if (ret != 0) {
|
||||
+ ERROR("Parse passwd error.");
|
||||
+ return ret;
|
||||
+ }
|
||||
+
|
||||
+ ret = hold_int(delim, required, &line, &result->pw_uid);
|
||||
+ if (ret != 0) {
|
||||
+ // a legitimate line must have uid
|
||||
+ ERROR("Parse uid error.");
|
||||
+ return ret;
|
||||
+ }
|
||||
+ ret = hold_int(delim, required, &line, &result->pw_gid);
|
||||
+ if (ret != 0) {
|
||||
+ // it's ok to not provide gid
|
||||
+ ERROR("Parse gid error.");
|
||||
+ }
|
||||
+
|
||||
+ ret = hold_string(delim, &line, &result->pw_gecos);
|
||||
+ if (ret != 0) {
|
||||
+ ERROR("Parse gecos error.");
|
||||
+ return ret;
|
||||
+ }
|
||||
+
|
||||
+ ret = hold_string(delim, &line, &result->pw_dir);
|
||||
+ if (ret != 0) {
|
||||
+ ERROR("Parse dir error.");
|
||||
+ return ret;
|
||||
+ }
|
||||
+
|
||||
+ ret = hold_string(delim, &line, &result->pw_shell);
|
||||
+ if (ret != 0) {
|
||||
+ ERROR("Parse shell error.");
|
||||
+ return ret;
|
||||
+ }
|
||||
+
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
+static char **hold_string_list(char **line, char *buf_start, char *buf_end, const char terminator)
|
||||
+{
|
||||
+ char **result = NULL;
|
||||
+ char **walker = NULL;
|
||||
+
|
||||
+ if (**line == '\0') {
|
||||
+ return 0;
|
||||
+ }
|
||||
+ // For ultimate space usage, the blank area from buffer which was allocated from stack is used
|
||||
+ buf_start += __alignof__(char *) - 1;
|
||||
+ // align the starting position of the buffer to use it as a 2d array
|
||||
+ buf_start -= (buf_start - (char *)0) % __alignof__(char *);
|
||||
+ // record the starting position for latter return
|
||||
+ result = (char **)buf_start;
|
||||
+ // set stop edge for the buffer
|
||||
+ walker = result;
|
||||
+
|
||||
+ for (; walker < (char **)buf_end; ++walker) {
|
||||
+ (void)util_trim_space(*line);
|
||||
+ if (hold_string(',', line, walker) != 0) {
|
||||
+ ERROR("Parse string list error.");
|
||||
+ return NULL;
|
||||
+ }
|
||||
+
|
||||
+ if ((char *)(walker + 2) > buf_end) {
|
||||
+ return NULL;
|
||||
+ }
|
||||
+
|
||||
+ if (**line == '\0') {
|
||||
+ return result;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ return result;
|
||||
+}
|
||||
+
|
||||
+static int parse_line_gr(const char delim, char *line, size_t buflen, struct group *result)
|
||||
+{
|
||||
+ int ret = 0;
|
||||
+ bool rf = false;
|
||||
+ char *freebuff = line + 1 + strlen(line);
|
||||
+ char *buffend = line + buflen;
|
||||
+
|
||||
+ ret = hold_string(delim, &line, &result->gr_name);
|
||||
+ if (ret != 0) {
|
||||
+ ERROR("Parse name error.");
|
||||
+ return ret;
|
||||
+ }
|
||||
+
|
||||
+ ret = hold_string(delim, &line, &result->gr_passwd);
|
||||
+ if (ret != 0) {
|
||||
+ ERROR("Parse gecos error.");
|
||||
+ return ret;
|
||||
+ }
|
||||
+ if (result->gr_name[0] == '+' || result->gr_name[0] == '-') {
|
||||
+ rf = true;
|
||||
+ }
|
||||
+
|
||||
+ ret = hold_int(delim, rf, &line, &result->gr_gid);
|
||||
+ if (ret != 0) {
|
||||
+ ERROR("Parse gid error.");
|
||||
+ return ret;
|
||||
+ }
|
||||
+
|
||||
+ result->gr_mem = hold_string_list(&line, freebuff, buffend, ',');
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+int util_getpwent_r(FILE *stream, struct passwd *resbuf, char *buffer, size_t buflen, struct passwd **result)
|
||||
+{
|
||||
+ const char delim = ':';
|
||||
+
|
||||
+ if (stream == NULL || resbuf == NULL || buffer == NULL) {
|
||||
+ ERROR("Password obj, params is NULL.");
|
||||
+ return -1;
|
||||
+ }
|
||||
+
|
||||
+ if (buflen <= 1) {
|
||||
+ ERROR("Inadiquate buffer length was given.");
|
||||
+ return -1;
|
||||
+ }
|
||||
+
|
||||
+ if (*result != NULL) {
|
||||
+ ERROR("Result shall point to null to start.");
|
||||
+ return -1;
|
||||
+ }
|
||||
+
|
||||
+ __fsetlocking(stream, FSETLOCKING_BYCALLER);
|
||||
+ buffer[buflen - 1] = '\0';
|
||||
+
|
||||
+ if (feof(stream)) {
|
||||
+ *result = NULL;
|
||||
+ return ENOENT;
|
||||
+ }
|
||||
+
|
||||
+ while (fgets(buffer, buflen, stream) != NULL) {
|
||||
+ (void)util_trim_space(buffer);
|
||||
+ if (buffer[0] == '\0' || buffer[0] == '#' || strlen(buffer) < 1) {
|
||||
+ continue;
|
||||
+ }
|
||||
+
|
||||
+ if (parse_line_pw(delim, buffer, resbuf) == 0) {
|
||||
+ break;
|
||||
+ }
|
||||
+
|
||||
+ if (buffer[buflen - 1] != '\0') {
|
||||
+ *result = NULL;
|
||||
+ return ERANGE;
|
||||
+ }
|
||||
+ }
|
||||
+ *result = resbuf;
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+int util_getgrent_r(FILE *stream, struct group *resbuf, char *buffer, size_t buflen, struct group **result)
|
||||
+{
|
||||
+ const char delim = ':';
|
||||
+
|
||||
+ if (stream == NULL || resbuf == NULL || buffer == NULL) {
|
||||
+ ERROR("Group obj, params is NULL.");
|
||||
+ return -1;
|
||||
+ }
|
||||
+
|
||||
+ if (buflen <= 1) {
|
||||
+ ERROR("Inadiquate buffer length was given.");
|
||||
+ return -1;
|
||||
+ }
|
||||
+
|
||||
+ if (*result != NULL) {
|
||||
+ ERROR("Result shall point to null to start.");
|
||||
+ return -1;
|
||||
+ }
|
||||
+
|
||||
+ __fsetlocking(stream, FSETLOCKING_BYCALLER);
|
||||
+ buffer[buflen - 1] = '\0';
|
||||
+
|
||||
+ if (feof(stream)) {
|
||||
+ *result = NULL;
|
||||
+ return ENOENT;
|
||||
+ }
|
||||
+
|
||||
+ while (fgets(buffer, buflen, stream) != NULL) {
|
||||
+ (void)util_trim_space(buffer);
|
||||
+ if (buffer[0] == '\0' || buffer[0] == '#' || strlen(buffer) < 1) {
|
||||
+ continue;
|
||||
+ }
|
||||
+
|
||||
+ if (parse_line_gr(delim, buffer, buflen, resbuf) == 0) {
|
||||
+ break;
|
||||
+ }
|
||||
+
|
||||
+ if (buffer[buflen - 1] != '\0') {
|
||||
+ *result = NULL;
|
||||
+ return ERANGE;
|
||||
+ }
|
||||
+ }
|
||||
+ *result = resbuf;
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
\ No newline at end of file
|
||||
diff --git a/src/utils/cutils/utils_pwgr.h b/src/utils/cutils/utils_pwgr.h
|
||||
new file mode 100644
|
||||
index 00000000..45e38059
|
||||
--- /dev/null
|
||||
+++ b/src/utils/cutils/utils_pwgr.h
|
||||
@@ -0,0 +1,33 @@
|
||||
+/******************************************************************************
|
||||
+ * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved.
|
||||
+ * iSulad licensed under the Mulan PSL v2.
|
||||
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
+ * You may obtain a copy of Mulan PSL v2 at:
|
||||
+ * http://license.coscl.org.cn/MulanPSL2
|
||||
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
||||
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
||||
+ * PURPOSE.
|
||||
+ * See the Mulan PSL v2 for more details.
|
||||
+ * Author: hejunjie
|
||||
+ * Create: 2022-04-08
|
||||
+ * Description: Provide line parser for android
|
||||
+ *******************************************************************************/
|
||||
+#ifndef UTILS_CUTILS_UTILS_PWGR_H
|
||||
+#define UTILS_CUTILS_UTILS_PWGR_H
|
||||
+
|
||||
+#include <stdio.h>
|
||||
+#include <pwd.h>
|
||||
+#include <grp.h>
|
||||
+
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
+int util_getpwent_r(FILE *stream, struct passwd *resbuf, char *buffer, size_t buflen, struct passwd **result);
|
||||
+
|
||||
+int util_getgrent_r(FILE *stream, struct group *resbuf, char *buffer, size_t buflen, struct group **result);
|
||||
+
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+#endif // UTILS_CUTILS_UTILS_PWGR_H
|
||||
diff --git a/test/cutils/CMakeLists.txt b/test/cutils/CMakeLists.txt
|
||||
index 826255cd..b549f844 100644
|
||||
--- a/test/cutils/CMakeLists.txt
|
||||
+++ b/test/cutils/CMakeLists.txt
|
||||
@@ -4,3 +4,4 @@ add_subdirectory(utils_string)
|
||||
add_subdirectory(utils_convert)
|
||||
add_subdirectory(utils_array)
|
||||
add_subdirectory(utils_base64)
|
||||
+add_subdirectory(utils_pwgr)
|
||||
diff --git a/test/cutils/utils_pwgr/CMakeLists.txt b/test/cutils/utils_pwgr/CMakeLists.txt
|
||||
new file mode 100644
|
||||
index 00000000..548718da
|
||||
--- /dev/null
|
||||
+++ b/test/cutils/utils_pwgr/CMakeLists.txt
|
||||
@@ -0,0 +1,29 @@
|
||||
+project(iSulad_UT)
|
||||
+
|
||||
+SET(EXE utils_pwgr_ut)
|
||||
+
|
||||
+add_executable(${EXE}
|
||||
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_string.c
|
||||
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils.c
|
||||
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_array.c
|
||||
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_file.c
|
||||
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_convert.c
|
||||
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_verify.c
|
||||
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_regex.c
|
||||
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_pwgr.c
|
||||
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/sha256/sha256.c
|
||||
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/map/map.c
|
||||
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/map/rb_tree.c
|
||||
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/path.c
|
||||
+ utils_pwgr_ut.cc)
|
||||
+
|
||||
+target_include_directories(${EXE} PUBLIC
|
||||
+ ${GTEST_INCLUDE_DIR}
|
||||
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../include
|
||||
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/common
|
||||
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/map
|
||||
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/sha256
|
||||
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils
|
||||
+ )
|
||||
+target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} -lcrypto -lyajl -lz)
|
||||
+add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
|
||||
diff --git a/test/cutils/utils_pwgr/group_sample b/test/cutils/utils_pwgr/group_sample
|
||||
new file mode 100644
|
||||
index 00000000..c73883cc
|
||||
--- /dev/null
|
||||
+++ b/test/cutils/utils_pwgr/group_sample
|
||||
@@ -0,0 +1,8 @@
|
||||
+root:x:0:
|
||||
+#bin:x:1:
|
||||
+
|
||||
+-adm:x:4:
|
||||
++adm:x:4:
|
||||
+adm:x:4:a,list,of,users
|
||||
+adm:x:4:are,split,by,comma
|
||||
+adm:x:4:root,john, boob,jason
|
||||
\ No newline at end of file
|
||||
diff --git a/test/cutils/utils_pwgr/passwd_sample b/test/cutils/utils_pwgr/passwd_sample
|
||||
new file mode 100644
|
||||
index 00000000..d4f3250d
|
||||
--- /dev/null
|
||||
+++ b/test/cutils/utils_pwgr/passwd_sample
|
||||
@@ -0,0 +1,11 @@
|
||||
+root:x:0:0:root:/root:/bin/bash
|
||||
+bin:x:1:1:bin:/bin:/sbin/nologin
|
||||
+bin:x:-1:1:bin:/bin:/sbin/nologin
|
||||
+uidonly:x:1::bin:/bin:/sbin/nologin
|
||||
+::::1:1:bin:/bin:/sbin/nologin
|
||||
+
|
||||
+#npt:*:66:77::/etc/ntp:/sbin/nologin
|
||||
+npt:*:66:77::/etc/ntp:/sbin/nologin
|
||||
+npt:*:66:77::/etc/ntp:/sbin/nologin:some:extra:context:added
|
||||
++npt:*::::/etc/ntp:/sbin/nologin
|
||||
+-npt:*::::/etc/ntp:/sbin/nologin
|
||||
\ No newline at end of file
|
||||
diff --git a/test/cutils/utils_pwgr/utils_pwgr_ut.cc b/test/cutils/utils_pwgr/utils_pwgr_ut.cc
|
||||
new file mode 100644
|
||||
index 00000000..1a121f88
|
||||
--- /dev/null
|
||||
+++ b/test/cutils/utils_pwgr/utils_pwgr_ut.cc
|
||||
@@ -0,0 +1,101 @@
|
||||
+/******************************************************************************
|
||||
+ * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved.
|
||||
+ * iSulad licensed under the Mulan PSL v2.
|
||||
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
+ * You may obtain a copy of Mulan PSL v2 at:
|
||||
+ * http://license.coscl.org.cn/MulanPSL2
|
||||
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
||||
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
||||
+ * PURPOSE.
|
||||
+ * See the Mulan PSL v2 for more details.
|
||||
+ * Author: hejunjie
|
||||
+ * Create: 2022-04-08
|
||||
+ * Description: utils_pwgr unit test
|
||||
+ *******************************************************************************/
|
||||
+
|
||||
+#include <gtest/gtest.h>
|
||||
+#include "utils_pwgr.h"
|
||||
+
|
||||
+TEST(utils_pwgr, test_getpwent_r)
|
||||
+{
|
||||
+ std::string path = "../../../../test/cutils/utils_pwgr/passwd_sample";
|
||||
+ FILE *f_pw = fopen(path.c_str(), "r");
|
||||
+ ASSERT_NE(f_pw, nullptr);
|
||||
+
|
||||
+ struct passwd pw;
|
||||
+ struct passwd *ppw = nullptr;
|
||||
+ char buf[BUFSIZ];
|
||||
+
|
||||
+ std::vector<std::tuple<std::string, std::string, int, int, std::string, std::string, std::string>> testcase = {
|
||||
+ std::make_tuple("root", "x", 0, 0, "root", "/root", "/bin/bash"),
|
||||
+ std::make_tuple("bin", "x", 1, 1, "bin", "/bin", "/sbin/nologin"),
|
||||
+ std::make_tuple("uidonly", "x", 1, 0, "bin", "/bin", "/sbin/nologin"),
|
||||
+ std::make_tuple("npt", "*", 66, 77, "", "/etc/ntp", "/sbin/nologin"),
|
||||
+ std::make_tuple("npt", "*", 66, 77, "", "/etc/ntp", "/sbin/nologin"),
|
||||
+ std::make_tuple("+npt", "*", 0, 0, "", "/etc/ntp", "/sbin/nologin"),
|
||||
+ std::make_tuple("-npt", "*", 0, 0, "", "/etc/ntp", "/sbin/nologin")
|
||||
+ };
|
||||
+
|
||||
+ for (const auto &elem : testcase) {
|
||||
+ ASSERT_EQ(util_getpwent_r(f_pw, &pw, buf, sizeof(buf), &ppw), 0);
|
||||
+ ASSERT_STREQ(pw.pw_name, std::get<0>(elem).c_str());
|
||||
+ ASSERT_STREQ(pw.pw_passwd, std::get<1>(elem).c_str());
|
||||
+ ASSERT_EQ(pw.pw_uid, std::get<2>(elem));
|
||||
+ ASSERT_EQ(pw.pw_gid, std::get<3>(elem));
|
||||
+ ASSERT_STREQ(pw.pw_gecos, std::get<4>(elem).c_str());
|
||||
+ ASSERT_STREQ(pw.pw_dir, std::get<5>(elem).c_str());
|
||||
+ ASSERT_STREQ(pw.pw_shell, std::get<6>(elem).c_str());
|
||||
+ EXPECT_TRUE(ppw == &pw);
|
||||
+ ppw = nullptr;
|
||||
+ pw = {0};
|
||||
+ }
|
||||
+
|
||||
+ fclose(f_pw);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_pwgr, test_getgrent_r)
|
||||
+{
|
||||
+ std::string path = "../../../../test/cutils/utils_pwgr/group_sample";
|
||||
+ FILE *f_gr = fopen(path.c_str(), "r");
|
||||
+ ASSERT_NE(f_gr, nullptr);
|
||||
+
|
||||
+ struct group gr{0};
|
||||
+ struct group *pgr = nullptr;
|
||||
+ char buf[BUFSIZ];
|
||||
+ size_t i = 0;
|
||||
+ size_t j = 0;
|
||||
+ std::vector<std::vector<std::string>> string_list{
|
||||
+ {}, {}, {},
|
||||
+ {"a", "list", "of", "users"},
|
||||
+ {"are", "split", "by", "comma"},
|
||||
+ {"root", "john", "boob", "jason"}
|
||||
+ };
|
||||
+
|
||||
+ std::vector<std::tuple<std::string, std::string, int>> testcase = {
|
||||
+ std::make_tuple("root", "x", 0),
|
||||
+ std::make_tuple("-adm", "x", 4),
|
||||
+ std::make_tuple("+adm", "x", 4),
|
||||
+ std::make_tuple("adm", "x", 4),
|
||||
+ std::make_tuple("adm", "x", 4),
|
||||
+ std::make_tuple("adm", "x", 4),
|
||||
+ };
|
||||
+
|
||||
+ for (; i < string_list.size(); ++i) {
|
||||
+ ASSERT_EQ(util_getgrent_r(f_gr, &gr, buf, sizeof(buf), &pgr), 0);
|
||||
+ ASSERT_STREQ(gr.gr_name, std::get<0>(testcase[i]).c_str());
|
||||
+ ASSERT_STREQ(gr.gr_passwd, std::get<1>(testcase[i]).c_str());
|
||||
+ ASSERT_EQ(gr.gr_gid, std::get<2>(testcase[i]));
|
||||
+ if (string_list[i].size()) {
|
||||
+ for (j = 0; j < string_list[i].size(); ++j) {
|
||||
+ EXPECT_TRUE(strcmp(gr.gr_mem[j], string_list[i][j].c_str()) == 0);
|
||||
+ }
|
||||
+ } else {
|
||||
+ EXPECT_TRUE(gr.gr_mem == nullptr);
|
||||
+ }
|
||||
+ EXPECT_TRUE(pgr == &gr);
|
||||
+ gr = {0};
|
||||
+ pgr = nullptr;
|
||||
+ }
|
||||
+
|
||||
+ fclose(f_gr);
|
||||
+}
|
||||
\ No newline at end of file
|
||||
--
|
||||
2.20.1
|
||||
|
||||
@ -1,111 +0,0 @@
|
||||
From a5c3e6064b583477de8564a20799a630474d556d Mon Sep 17 00:00:00 2001
|
||||
From: wujing <wujing50@huawei.com>
|
||||
Date: Tue, 29 Mar 2022 20:07:31 +0800
|
||||
Subject: [PATCH 06/16] test: adapt to the enabled selinux host environment
|
||||
|
||||
Signed-off-by: wujing <wujing50@huawei.com>
|
||||
---
|
||||
test/services/execution/spec/CMakeLists.txt | 2 +
|
||||
.../execution/spec/selinux_label_ut.cc | 48 ++++++++++++++++---
|
||||
2 files changed, 43 insertions(+), 7 deletions(-)
|
||||
|
||||
diff --git a/test/services/execution/spec/CMakeLists.txt b/test/services/execution/spec/CMakeLists.txt
|
||||
index 9ce30219..e1aa680e 100644
|
||||
--- a/test/services/execution/spec/CMakeLists.txt
|
||||
+++ b/test/services/execution/spec/CMakeLists.txt
|
||||
@@ -15,6 +15,7 @@ add_executable(${EXE}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/utils/cutils/path.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/utils/cutils/map/map.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/utils/cutils/map/rb_tree.c
|
||||
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/utils/cpputils/cxxutils.cc
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/common/err_msg.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../../mocks/namespace_mock.cc
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/common/selinux_label.c
|
||||
@@ -46,6 +47,7 @@ target_include_directories(${EXE} PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/common
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../../include
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/utils/cutils
|
||||
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/utils/cpputils
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/utils/sha256
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/utils/cutils/map
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/daemon/services/execution/manager
|
||||
diff --git a/test/services/execution/spec/selinux_label_ut.cc b/test/services/execution/spec/selinux_label_ut.cc
|
||||
index ea3c480c..c0e9ab1c 100644
|
||||
--- a/test/services/execution/spec/selinux_label_ut.cc
|
||||
+++ b/test/services/execution/spec/selinux_label_ut.cc
|
||||
@@ -25,6 +25,7 @@
|
||||
#include <sys/stat.h>
|
||||
#include "namespace_mock.h"
|
||||
#include "utils.h"
|
||||
+#include "cxxutils.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -40,6 +41,34 @@ protected:
|
||||
}
|
||||
};
|
||||
|
||||
+std::string get_lxc_context_filed(const std::string &filed)
|
||||
+{
|
||||
+ ifstream in("/etc/selinux/targeted/contexts/lxc_contexts");
|
||||
+ string line;
|
||||
+ while (getline(in, line)) {
|
||||
+ stringstream ss(line);
|
||||
+ string tmp;
|
||||
+ while (getline(ss, tmp)) {
|
||||
+ auto configs = CXXUtils::Split(tmp, '=');
|
||||
+ if (configs.size() != 2) {
|
||||
+ return "";
|
||||
+ }
|
||||
+ if (configs.at(0).substr(0, filed.size()) != filed) {
|
||||
+ continue;
|
||||
+ }
|
||||
+
|
||||
+ auto elements = CXXUtils::Split(configs.at(1), ':');
|
||||
+ if (elements.size() < 3) {
|
||||
+ return "";
|
||||
+ }
|
||||
+
|
||||
+ return elements.at(2);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ return "";
|
||||
+}
|
||||
+
|
||||
TEST_F(SELinuxLabelUnitTest, test_init_label_normal)
|
||||
{
|
||||
const char *disable_label[] = { "disable" };
|
||||
@@ -48,17 +77,22 @@ TEST_F(SELinuxLabelUnitTest, test_init_label_normal)
|
||||
const char *type_label[] = { "type:faketype" };
|
||||
const char *level_label[] = { "level:s0:c1,c2" };
|
||||
const char *full_label[] = { "user:fakeuser", "level:s0:c1,c2", "type:faketype", "role:fakerole" };
|
||||
+ std::string process_context = get_lxc_context_filed("process");
|
||||
+ std::string file_context = get_lxc_context_filed("file");
|
||||
|
||||
std::vector<std::tuple<const char **, size_t, int, std::string, std::string>> normal {
|
||||
std::make_tuple(disable_label, 1, 0, "", ""),
|
||||
- std::make_tuple(user_label, 1, 0, "fakeuser:system_r:container_t:s0", "fakeuser:object_r:container_file_t:s0"),
|
||||
- std::make_tuple(role_label, 1, 0, "system_u:fakerole:container_t:s0", "system_u:object_r:container_file_t:s0"),
|
||||
- std::make_tuple(type_label, 1, 0, "system_u:system_r:faketype:s0", "system_u:object_r:container_file_t:s0"),
|
||||
- std::make_tuple(level_label, 1, 0, "system_u:system_r:container_t:s0:c1,c2",
|
||||
- "system_u:object_r:container_file_t:s0:c1,c2"),
|
||||
+ std::make_tuple(user_label, 1, 0, "fakeuser:system_r:" + process_context + ":s0",
|
||||
+ "fakeuser:object_r:" + file_context + ":s0"),
|
||||
+ std::make_tuple(role_label, 1, 0, "system_u:fakerole:" + process_context + ":s0",
|
||||
+ "system_u:object_r:" + file_context + ":s0"),
|
||||
+ std::make_tuple(type_label, 1, 0, "system_u:system_r:faketype:s0", "system_u:object_r:" + file_context + ":s0"),
|
||||
+ std::make_tuple(level_label, 1, 0, "system_u:system_r:" + process_context + ":s0:c1,c2",
|
||||
+ "system_u:object_r:" + file_context + ":s0:c1,c2"),
|
||||
std::make_tuple(full_label, 4, 0, "fakeuser:fakerole:faketype:s0:c1,c2",
|
||||
- "fakeuser:object_r:container_file_t:s0:c1,c2"),
|
||||
- std::make_tuple(nullptr, 0, 0, "system_u:system_r:container_t:s0", "system_u:object_r:container_file_t:s0"),
|
||||
+ "fakeuser:object_r:" + file_context + ":s0:c1,c2"),
|
||||
+ std::make_tuple(nullptr, 0, 0, "system_u:system_r:" + process_context + ":s0",
|
||||
+ "system_u:object_r:" + file_context + ":s0"),
|
||||
};
|
||||
|
||||
if (!is_selinux_enabled()) {
|
||||
--
|
||||
2.20.1
|
||||
|
||||
@ -1,98 +0,0 @@
|
||||
From ef8bec5f8c3d7b60d2d5148f3386f00c3a29ffc2 Mon Sep 17 00:00:00 2001
|
||||
From: chegJH <hejunjie10@huawei.com>
|
||||
Date: Tue, 10 May 2022 18:06:53 +0800
|
||||
Subject: [PATCH 07/16] Adapt to bionic libc, improve lcov coverage
|
||||
|
||||
Signed-off-by: chegJH <hejunjie10@huawei.com>
|
||||
---
|
||||
src/utils/cutils/CMakeLists.txt | 4 ++++
|
||||
test/cutils/utils_pwgr/passwd_sample | 1 +
|
||||
test/cutils/utils_pwgr/utils_pwgr_ut.cc | 24 ++++++++++++++++++++++++
|
||||
3 files changed, 29 insertions(+)
|
||||
|
||||
diff --git a/src/utils/cutils/CMakeLists.txt b/src/utils/cutils/CMakeLists.txt
|
||||
index 0ecad671..30414d91 100644
|
||||
--- a/src/utils/cutils/CMakeLists.txt
|
||||
+++ b/src/utils/cutils/CMakeLists.txt
|
||||
@@ -2,6 +2,10 @@
|
||||
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} local_cutils_srcs)
|
||||
add_subdirectory(map)
|
||||
|
||||
+if (NOT ANDROID)
|
||||
+ list(REMOVE_ITEM local_cutils_srcs "${CMAKE_CURRENT_SOURCE_DIR}/utils_pwgr.c")
|
||||
+endif()
|
||||
+
|
||||
set(CUTILS_SRCS
|
||||
${local_cutils_srcs}
|
||||
${MAP_SRCS}
|
||||
diff --git a/test/cutils/utils_pwgr/passwd_sample b/test/cutils/utils_pwgr/passwd_sample
|
||||
index d4f3250d..76853454 100644
|
||||
--- a/test/cutils/utils_pwgr/passwd_sample
|
||||
+++ b/test/cutils/utils_pwgr/passwd_sample
|
||||
@@ -3,6 +3,7 @@ bin:x:1:1:bin:/bin:/sbin/nologin
|
||||
bin:x:-1:1:bin:/bin:/sbin/nologin
|
||||
uidonly:x:1::bin:/bin:/sbin/nologin
|
||||
::::1:1:bin:/bin:/sbin/nologin
|
||||
+root:x:
|
||||
|
||||
#npt:*:66:77::/etc/ntp:/sbin/nologin
|
||||
npt:*:66:77::/etc/ntp:/sbin/nologin
|
||||
diff --git a/test/cutils/utils_pwgr/utils_pwgr_ut.cc b/test/cutils/utils_pwgr/utils_pwgr_ut.cc
|
||||
index 1a121f88..1ed8eaa1 100644
|
||||
--- a/test/cutils/utils_pwgr/utils_pwgr_ut.cc
|
||||
+++ b/test/cutils/utils_pwgr/utils_pwgr_ut.cc
|
||||
@@ -24,6 +24,7 @@ TEST(utils_pwgr, test_getpwent_r)
|
||||
|
||||
struct passwd pw;
|
||||
struct passwd *ppw = nullptr;
|
||||
+ struct passwd *ppw_alter = &pw;
|
||||
char buf[BUFSIZ];
|
||||
|
||||
std::vector<std::tuple<std::string, std::string, int, int, std::string, std::string, std::string>> testcase = {
|
||||
@@ -36,6 +37,17 @@ TEST(utils_pwgr, test_getpwent_r)
|
||||
std::make_tuple("-npt", "*", 0, 0, "", "/etc/ntp", "/sbin/nologin")
|
||||
};
|
||||
|
||||
+ ASSERT_EQ(util_getpwent_r(NULL, &pw, buf, sizeof(buf), &ppw), -1);
|
||||
+ ASSERT_EQ(util_getpwent_r(f_pw, &pw, NULL, 0, &ppw), -1);
|
||||
+ ASSERT_EQ(util_getpwent_r(f_pw, &pw, NULL, 1, &ppw), -1);
|
||||
+ ASSERT_EQ(util_getpwent_r(f_pw, &pw, buf, sizeof(buf), &ppw_alter), -1);
|
||||
+
|
||||
+ while (!feof(f_pw)) {
|
||||
+ (void)getc(f_pw);
|
||||
+ }
|
||||
+ ASSERT_EQ(util_getpwent_r(f_pw, &pw, buf, sizeof(buf), &ppw), ENOENT);
|
||||
+ rewind(f_pw);
|
||||
+
|
||||
for (const auto &elem : testcase) {
|
||||
ASSERT_EQ(util_getpwent_r(f_pw, &pw, buf, sizeof(buf), &ppw), 0);
|
||||
ASSERT_STREQ(pw.pw_name, std::get<0>(elem).c_str());
|
||||
@@ -61,6 +73,7 @@ TEST(utils_pwgr, test_getgrent_r)
|
||||
|
||||
struct group gr{0};
|
||||
struct group *pgr = nullptr;
|
||||
+ struct group *pgr_alter = &gr;
|
||||
char buf[BUFSIZ];
|
||||
size_t i = 0;
|
||||
size_t j = 0;
|
||||
@@ -80,6 +93,17 @@ TEST(utils_pwgr, test_getgrent_r)
|
||||
std::make_tuple("adm", "x", 4),
|
||||
};
|
||||
|
||||
+ ASSERT_EQ(util_getgrent_r(NULL, &gr, buf, sizeof(buf), &pgr), -1);
|
||||
+ ASSERT_EQ(util_getgrent_r(f_gr, &gr, NULL, 0, &pgr), -1);
|
||||
+ ASSERT_EQ(util_getgrent_r(f_gr, &gr, NULL, 1, &pgr), -1);
|
||||
+ ASSERT_EQ(util_getgrent_r(f_gr, &gr, buf, sizeof(buf), &pgr_alter), -1);
|
||||
+
|
||||
+ while (!feof(f_gr)) {
|
||||
+ (void)getc(f_gr);
|
||||
+ }
|
||||
+ ASSERT_EQ(util_getgrent_r(f_gr, &gr, buf, sizeof(buf), &pgr), ENOENT);
|
||||
+ rewind(f_gr);
|
||||
+
|
||||
for (; i < string_list.size(); ++i) {
|
||||
ASSERT_EQ(util_getgrent_r(f_gr, &gr, buf, sizeof(buf), &pgr), 0);
|
||||
ASSERT_STREQ(gr.gr_name, std::get<0>(testcase[i]).c_str());
|
||||
--
|
||||
2.20.1
|
||||
|
||||
@ -1,87 +0,0 @@
|
||||
From 16bfb6e4a4deb5164f8644de3b76129e428653c7 Mon Sep 17 00:00:00 2001
|
||||
From: wujing <wujing50@huawei.com>
|
||||
Date: Mon, 17 Jan 2022 11:24:05 +0800
|
||||
Subject: [PATCH 08/16] fix cmd/isulad-shim module encoding problem
|
||||
|
||||
Signed-off-by: wujing <wujing50@huawei.com>
|
||||
---
|
||||
src/cmd/isulad-shim/common.c | 2 --
|
||||
src/cmd/isulad-shim/common.h | 17 ++++++++---------
|
||||
src/cmd/isulad-shim/process.c | 4 +---
|
||||
3 files changed, 9 insertions(+), 14 deletions(-)
|
||||
|
||||
diff --git a/src/cmd/isulad-shim/common.c b/src/cmd/isulad-shim/common.c
|
||||
index 324d72a1..20e0963c 100644
|
||||
--- a/src/cmd/isulad-shim/common.c
|
||||
+++ b/src/cmd/isulad-shim/common.c
|
||||
@@ -236,8 +236,6 @@ void write_message(int fd, const char *level, const char *fmt, ...)
|
||||
if (nwrite != strlen(msg)) {
|
||||
return;
|
||||
}
|
||||
-
|
||||
- return;
|
||||
}
|
||||
|
||||
/* note: This function can only read small text file. */
|
||||
diff --git a/src/cmd/isulad-shim/common.h b/src/cmd/isulad-shim/common.h
|
||||
index 8c6ea7ba..d06c5256 100644
|
||||
--- a/src/cmd/isulad-shim/common.h
|
||||
+++ b/src/cmd/isulad-shim/common.h
|
||||
@@ -26,19 +26,19 @@ extern "C" {
|
||||
|
||||
// error code
|
||||
#define SHIM_ERR_BASE (-10000)
|
||||
-#define SHIM_SYS_ERR(err) (SHIM_ERR_BASE-err)
|
||||
-#define SHIM_OK 0
|
||||
-#define SHIM_ERR -1
|
||||
-#define SHIM_ERR_WAIT -2
|
||||
-#define SHIM_ERR_NOT_REQUIRED -3
|
||||
+#define SHIM_SYS_ERR(err) (SHIM_ERR_BASE - err)
|
||||
+#define SHIM_OK 0
|
||||
+#define SHIM_ERR (-1)
|
||||
+#define SHIM_ERR_WAIT (-2)
|
||||
+#define SHIM_ERR_NOT_REQUIRED (-3)
|
||||
|
||||
#define INFO_MSG "info"
|
||||
#define WARN_MSG "warn"
|
||||
#define ERR_MSG "error"
|
||||
|
||||
-#define DEFAULT_TIMEOUT 120 // sec
|
||||
-#define CONTAINER_ID_LEN 64
|
||||
-#define MAX_RT_NAME_LEN 64
|
||||
+#define DEFAULT_TIMEOUT 120 // sec
|
||||
+#define CONTAINER_ID_LEN 64
|
||||
+#define MAX_RT_NAME_LEN 64
|
||||
#define MAX_CONSOLE_SOCK_LEN 32
|
||||
|
||||
#define MAX_RUNTIME_ARGS 20
|
||||
@@ -73,4 +73,3 @@ int open_no_inherit(const char *path, int flag, mode_t mode);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
-
|
||||
diff --git a/src/cmd/isulad-shim/process.c b/src/cmd/isulad-shim/process.c
|
||||
index b3014d7a..21b2523a 100644
|
||||
--- a/src/cmd/isulad-shim/process.c
|
||||
+++ b/src/cmd/isulad-shim/process.c
|
||||
@@ -351,8 +351,6 @@ static void sem_post_inotify_io_copy(int fd, uint32_t event, void *data)
|
||||
thd->shutdown = true;
|
||||
(void)sem_post(&thd->sem_thd);
|
||||
}
|
||||
-
|
||||
- return;
|
||||
}
|
||||
|
||||
static int create_io_copy_thread(process_t *p, int std_id)
|
||||
@@ -1029,7 +1027,7 @@ static void process_delete(process_t *p)
|
||||
int i = 0;
|
||||
int j;
|
||||
char log_path[PATH_MAX] = { 0 };
|
||||
- char *cwd;
|
||||
+ char *cwd = NULL;
|
||||
|
||||
cwd = getcwd(NULL, 0);
|
||||
if (cwd == NULL) {
|
||||
--
|
||||
2.20.1
|
||||
|
||||
@ -1,521 +0,0 @@
|
||||
From dff4e8fc306e2270695c20434f79bcf3303c8f37 Mon Sep 17 00:00:00 2001
|
||||
From: wujing <wujing50@huawei.com>
|
||||
Date: Tue, 18 Jan 2022 17:21:15 +0800
|
||||
Subject: [PATCH 09/16] fix utils module encoding problem
|
||||
|
||||
Signed-off-by: wujing <wujing50@huawei.com>
|
||||
---
|
||||
src/utils/console/console.c | 2 +-
|
||||
src/utils/console/console.h | 4 +-
|
||||
src/utils/cpputils/stoppable_thread.cc | 7 +--
|
||||
src/utils/cpputils/stoppable_thread.h | 15 ++++---
|
||||
src/utils/cpputils/url.cc | 61 ++++++++++++--------------
|
||||
src/utils/cutils/utils_aes.c | 4 +-
|
||||
src/utils/cutils/utils_mount_spec.c | 41 ++++++++---------
|
||||
src/utils/cutils/utils_string.c | 4 +-
|
||||
src/utils/cutils/utils_timestamp.c | 11 +++--
|
||||
9 files changed, 73 insertions(+), 76 deletions(-)
|
||||
|
||||
diff --git a/src/utils/console/console.c b/src/utils/console/console.c
|
||||
index b1d8b6dc..17c8b242 100644
|
||||
--- a/src/utils/console/console.c
|
||||
+++ b/src/utils/console/console.c
|
||||
@@ -437,7 +437,7 @@ err_out:
|
||||
|
||||
/* console loop copy */
|
||||
int console_loop_io_copy(int sync_fd, const int *srcfds, struct io_write_wrapper *writers,
|
||||
- transfer_channel_type *channels, size_t len)
|
||||
+ const transfer_channel_type *channels, size_t len)
|
||||
{
|
||||
int ret = 0;
|
||||
size_t i = 0;
|
||||
diff --git a/src/utils/console/console.h b/src/utils/console/console.h
|
||||
index 63103d2b..f42ec994 100644
|
||||
--- a/src/utils/console/console.h
|
||||
+++ b/src/utils/console/console.h
|
||||
@@ -43,7 +43,7 @@ struct tty_state {
|
||||
bool ignore_stdin_close;
|
||||
};
|
||||
|
||||
-typedef enum { STDIN_CHANNEL, STDOUT_CHANNEL, STDERR_CHANNEL, MAX_CHANNEL} transfer_channel_type;
|
||||
+typedef enum { STDIN_CHANNEL, STDOUT_CHANNEL, STDERR_CHANNEL, MAX_CHANNEL } transfer_channel_type;
|
||||
|
||||
int console_fifo_name(const char *rundir, const char *subpath, const char *stdflag, char *fifo_name,
|
||||
size_t fifo_name_sz, char *fifo_path, size_t fifo_path_sz, bool do_mkdirp);
|
||||
@@ -62,7 +62,7 @@ int console_loop_with_std_fd(int stdinfd, int stdoutfd, int stderrfd, int fifoin
|
||||
int tty_exit, bool tty);
|
||||
|
||||
int console_loop_io_copy(int sync_fd, const int *srcfds, struct io_write_wrapper *writers,
|
||||
- transfer_channel_type *channels, size_t len);
|
||||
+ const transfer_channel_type *channels, size_t len);
|
||||
|
||||
int setup_tios(int fd, struct termios *curr_tios);
|
||||
|
||||
diff --git a/src/utils/cpputils/stoppable_thread.cc b/src/utils/cpputils/stoppable_thread.cc
|
||||
index 68f6d9b2..20c6b374 100644
|
||||
--- a/src/utils/cpputils/stoppable_thread.cc
|
||||
+++ b/src/utils/cpputils/stoppable_thread.cc
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
#include "stoppable_thread.h"
|
||||
|
||||
-StoppableThread &StoppableThread::operator=(StoppableThread &&obj)
|
||||
+StoppableThread &StoppableThread::operator=(StoppableThread &&obj) noexcept
|
||||
{
|
||||
m_exit_signal = std::move(obj.m_exit_signal);
|
||||
m_future_obj = std::move(obj.m_future_obj);
|
||||
@@ -24,10 +24,7 @@ StoppableThread &StoppableThread::operator=(StoppableThread &&obj)
|
||||
|
||||
bool StoppableThread::stopRequested()
|
||||
{
|
||||
- if (m_future_obj.wait_for(std::chrono::milliseconds(0)) == std::future_status::timeout) {
|
||||
- return false;
|
||||
- }
|
||||
- return true;
|
||||
+ return m_future_obj.wait_for(std::chrono::milliseconds(0)) != std::future_status::timeout;
|
||||
}
|
||||
|
||||
void StoppableThread::stop()
|
||||
diff --git a/src/utils/cpputils/stoppable_thread.h b/src/utils/cpputils/stoppable_thread.h
|
||||
index 7dfd61f9..f5f4fb3f 100644
|
||||
--- a/src/utils/cpputils/stoppable_thread.h
|
||||
+++ b/src/utils/cpputils/stoppable_thread.h
|
||||
@@ -23,12 +23,18 @@
|
||||
|
||||
class StoppableThread {
|
||||
public:
|
||||
- StoppableThread() : m_future_obj(m_exit_signal.get_future()) {}
|
||||
+ StoppableThread()
|
||||
+ : m_future_obj(m_exit_signal.get_future())
|
||||
+ {
|
||||
+ }
|
||||
|
||||
- explicit StoppableThread(StoppableThread &&obj) : m_exit_signal(std::move(obj.m_exit_signal)),
|
||||
- m_future_obj(std::move(obj.m_future_obj)) {}
|
||||
+ explicit StoppableThread(StoppableThread &&obj) noexcept
|
||||
+ : m_exit_signal(std::move(obj.m_exit_signal))
|
||||
+ , m_future_obj(std::move(obj.m_future_obj))
|
||||
+ {
|
||||
+ }
|
||||
|
||||
- StoppableThread &operator=(StoppableThread &&obj);
|
||||
+ StoppableThread &operator=(StoppableThread &&obj) noexcept;
|
||||
|
||||
virtual ~StoppableThread() = default;
|
||||
|
||||
@@ -49,4 +55,3 @@ private:
|
||||
};
|
||||
|
||||
#endif // UTILS_CPPUTILS_STOPPABLE_THREAD_H
|
||||
-
|
||||
diff --git a/src/utils/cpputils/url.cc b/src/utils/cpputils/url.cc
|
||||
index 39032feb..ab1355a3 100644
|
||||
--- a/src/utils/cpputils/url.cc
|
||||
+++ b/src/utils/cpputils/url.cc
|
||||
@@ -109,7 +109,7 @@ int UnescapeDealWithPercentSign(size_t &i, std::string &s, const EncodeMode &mod
|
||||
if (s.length() > 3) {
|
||||
s.erase(s.begin() + 3, s.end());
|
||||
}
|
||||
- ERROR("invalid URL escape %s", s.c_str()); // quoted
|
||||
+ ERROR("invalid URL escape %s", s.c_str()); // quoted
|
||||
return -1;
|
||||
}
|
||||
char s1, s2;
|
||||
@@ -123,10 +123,10 @@ int UnescapeDealWithPercentSign(size_t &i, std::string &s, const EncodeMode &mod
|
||||
}
|
||||
if (mode == EncodeMode::ENCODE_ZONE) {
|
||||
char v = static_cast<char>((static_cast<unsigned char>(s1) << 4) | static_cast<unsigned char>(s2));
|
||||
- if (std::string(s.begin() + static_cast<long>(i), s.begin() + static_cast<long>(i) + 3) != "%25" &&
|
||||
- v != ' ' && ShouldEscape(v, EncodeMode::ENCODE_HOST)) {
|
||||
- ERROR("invalid URL escape %s", std::string(s.begin() + static_cast<long>(i),
|
||||
- s.begin() + static_cast<long>(i) + 3).c_str());
|
||||
+ if (std::string(s.begin() + static_cast<long>(i), s.begin() + static_cast<long>(i) + 3) != "%25" && v != ' ' &&
|
||||
+ ShouldEscape(v, EncodeMode::ENCODE_HOST)) {
|
||||
+ ERROR("invalid URL escape %s",
|
||||
+ std::string(s.begin() + static_cast<long>(i), s.begin() + static_cast<long>(i) + 3).c_str());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -153,8 +153,8 @@ int CalculatePercentNum(std::string &s, const EncodeMode &mode, bool &hasPlus)
|
||||
}
|
||||
break;
|
||||
default:
|
||||
- if ((mode == EncodeMode::ENCODE_HOST || mode == EncodeMode::ENCODE_ZONE) &&
|
||||
- int(s[i]) < 0x80 && ShouldEscape(s[i], mode)) {
|
||||
+ if ((mode == EncodeMode::ENCODE_HOST || mode == EncodeMode::ENCODE_ZONE) && int(s[i]) < 0x80 &&
|
||||
+ ShouldEscape(s[i], mode)) {
|
||||
ERROR("invalid URL escape %s", std::string(s.begin() + (long)i, s.begin() + (long)i + 1).c_str());
|
||||
return -1;
|
||||
}
|
||||
@@ -319,7 +319,7 @@ URLDatum *Parse(const std::string &rawurl)
|
||||
{
|
||||
std::string u, frag;
|
||||
Split(rawurl, "#", true, u, frag);
|
||||
- auto url = Parse(u, false);
|
||||
+ auto *url = Parse(u, false);
|
||||
if (url == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
@@ -335,12 +335,11 @@ URLDatum *Parse(const std::string &rawurl)
|
||||
|
||||
int SplitOffPossibleLeading(std::string &scheme, const std::string &rawurl, URLDatum *url, std::string &rest)
|
||||
{
|
||||
- if (Getscheme(rawurl, scheme, rest)) {
|
||||
+ if (Getscheme(rawurl, scheme, rest) != 0) {
|
||||
return -1;
|
||||
}
|
||||
std::transform(scheme.begin(), scheme.end(), scheme.begin(), ::tolower);
|
||||
- if (rest.at(rest.length() - 1) == '?' &&
|
||||
- std::count(rest.begin(), rest.end(), '?') == 1) {
|
||||
+ if (rest.at(rest.length() - 1) == '?' && std::count(rest.begin(), rest.end(), '?') == 1) {
|
||||
url->SetForceQuery(true);
|
||||
rest = rest.substr(0, rest.length() - 1);
|
||||
} else {
|
||||
@@ -351,8 +350,8 @@ int SplitOffPossibleLeading(std::string &scheme, const std::string &rawurl, URLD
|
||||
return 0;
|
||||
}
|
||||
|
||||
-URLDatum *HandleNonBackslashPrefix(URLDatum *url, const std::string &scheme,
|
||||
- const std::string &rest, bool viaRequest, bool &should_ret)
|
||||
+URLDatum *HandleNonBackslashPrefix(URLDatum *url, const std::string &scheme, const std::string &rest, bool viaRequest,
|
||||
+ bool &should_ret)
|
||||
{
|
||||
if (rest.at(0) == '/') {
|
||||
return nullptr;
|
||||
@@ -403,7 +402,7 @@ URLDatum *Parse(const std::string &rawurl, bool viaRequest)
|
||||
ERROR("empty url!");
|
||||
return nullptr;
|
||||
}
|
||||
- URLDatum *url = new (std::nothrow) URLDatum;
|
||||
+ auto *url = new (std::nothrow) URLDatum;
|
||||
if (url == nullptr) {
|
||||
ERROR("Out of memory");
|
||||
return nullptr;
|
||||
@@ -414,15 +413,15 @@ URLDatum *Parse(const std::string &rawurl, bool viaRequest)
|
||||
}
|
||||
std::string scheme = url->GetScheme();
|
||||
std::string rest;
|
||||
- if (SplitOffPossibleLeading(scheme, rawurl, url, rest)) {
|
||||
+ if (SplitOffPossibleLeading(scheme, rawurl, url, rest) != 0) {
|
||||
return nullptr;
|
||||
}
|
||||
bool should_ret = false;
|
||||
- auto tmpret = HandleNonBackslashPrefix(url, scheme, rest, viaRequest, should_ret);
|
||||
+ auto *tmpret = HandleNonBackslashPrefix(url, scheme, rest, viaRequest, should_ret);
|
||||
if (should_ret) {
|
||||
return tmpret;
|
||||
}
|
||||
- if (SetURLDatumInfo(url, scheme, viaRequest, rest)) {
|
||||
+ if (SetURLDatumInfo(url, scheme, viaRequest, rest) != 0) {
|
||||
return nullptr;
|
||||
}
|
||||
return url;
|
||||
@@ -432,13 +431,13 @@ int ParseAuthority(const std::string &authority, UserInfo **user, std::string &h
|
||||
{
|
||||
size_t i = authority.find("@");
|
||||
if (i == std::string::npos) {
|
||||
- if (ParseHost(authority, host)) {
|
||||
+ if (ParseHost(authority, host) != 0) {
|
||||
*user = nullptr;
|
||||
host = "";
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
- if (ParseHost(authority.substr(i + 1, authority.size()), host)) {
|
||||
+ if (ParseHost(authority.substr(i + 1, authority.size()), host) != 0) {
|
||||
*user = nullptr;
|
||||
host = "";
|
||||
return -1;
|
||||
@@ -602,7 +601,7 @@ std::string GetFullPreResolvePath(const std::string &base, const std::string &re
|
||||
void SplitFullPreResolvePath(const std::string &full, std::vector<std::string> &dst)
|
||||
{
|
||||
std::vector<std::string> src = CXXUtils::Split(full, '/');
|
||||
- for (auto elem : src) {
|
||||
+ for (const auto &elem : src) {
|
||||
if (elem == ".") {
|
||||
continue;
|
||||
} else if (elem == "..") {
|
||||
@@ -676,8 +675,8 @@ bool ValidUserinfo(const std::string &s)
|
||||
{
|
||||
std::string subDelims = R"(-._:~!$&'()*+,;=%@)";
|
||||
for (const auto &r : s) {
|
||||
- if (('A' <= r && r <= 'Z') || ('a' <= r && r <= 'z') ||
|
||||
- ('0' <= r && r <= '9') || (subDelims.find(r) != std::string::npos)) {
|
||||
+ if (('A' <= r && r <= 'Z') || ('a' <= r && r <= 'z') || ('0' <= r && r <= '9') ||
|
||||
+ (subDelims.find(r) != std::string::npos)) {
|
||||
continue;
|
||||
}
|
||||
return false;
|
||||
@@ -687,11 +686,11 @@ bool ValidUserinfo(const std::string &s)
|
||||
|
||||
std::string Values::Get(const std::string &key)
|
||||
{
|
||||
- if (v.size() == 0) {
|
||||
+ if (v.empty()) {
|
||||
return "";
|
||||
}
|
||||
std::vector<std::string> vs = v[key];
|
||||
- if (vs.size() == 0) {
|
||||
+ if (vs.empty()) {
|
||||
return "";
|
||||
}
|
||||
return vs[0];
|
||||
@@ -731,7 +730,7 @@ std::string Values::Encode()
|
||||
for (auto k : keys) {
|
||||
std::vector<std::string> vs = v[k];
|
||||
std::string keyEscaped = QueryEscape(k);
|
||||
- for (auto elem : vs) {
|
||||
+ for (const auto &elem : vs) {
|
||||
if (buf.length() > 0) {
|
||||
buf.append("&");
|
||||
}
|
||||
@@ -817,8 +816,7 @@ void URLDatum::StringOpaqueEmptyRules(std::string &buf)
|
||||
}
|
||||
if (buf.length() == 0) {
|
||||
auto i = m_path.find(":");
|
||||
- if (i != std::string::npos &&
|
||||
- path.substr(0, i).find("/") == std::string::npos) {
|
||||
+ if (i != std::string::npos && path.substr(0, i).find("/") == std::string::npos) {
|
||||
buf.append("./");
|
||||
}
|
||||
}
|
||||
@@ -855,7 +853,7 @@ bool URLDatum::IsAbs() const
|
||||
|
||||
std::unique_ptr<URLDatum> URLDatum::UrlParse(const std::string &ref)
|
||||
{
|
||||
- auto refurl = Parse(ref);
|
||||
+ auto *refurl = Parse(ref);
|
||||
if (refurl == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
@@ -894,8 +892,7 @@ std::unique_ptr<URLDatum> URLDatum::ResolveReference(URLDatum *ref)
|
||||
return url;
|
||||
}
|
||||
|
||||
-
|
||||
-auto URLDatum::Query() ->std::map<std::string, std::vector<std::string>>
|
||||
+auto URLDatum::Query() -> std::map<std::string, std::vector<std::string>>
|
||||
{
|
||||
return ParseQuery(m_rawQuery);
|
||||
}
|
||||
@@ -928,6 +925,4 @@ std::string URLDatum::Port() const
|
||||
{
|
||||
return PortOnly(m_host);
|
||||
}
|
||||
-} // namespace url
|
||||
-
|
||||
-
|
||||
+} // namespace url
|
||||
diff --git a/src/utils/cutils/utils_aes.c b/src/utils/cutils/utils_aes.c
|
||||
index 1df95fd5..5dc822a2 100644
|
||||
--- a/src/utils/cutils/utils_aes.c
|
||||
+++ b/src/utils/cutils/utils_aes.c
|
||||
@@ -95,9 +95,9 @@ size_t util_aes_decode_buf_len(size_t len)
|
||||
{
|
||||
if (len % AES_BLOCK_SIZE == 0) {
|
||||
return len;
|
||||
- } else {
|
||||
- return (len / AES_BLOCK_SIZE * AES_BLOCK_SIZE) + AES_BLOCK_SIZE;
|
||||
}
|
||||
+
|
||||
+ return (len / AES_BLOCK_SIZE * AES_BLOCK_SIZE) + AES_BLOCK_SIZE;
|
||||
}
|
||||
|
||||
size_t util_aes_encode_buf_len(size_t len)
|
||||
diff --git a/src/utils/cutils/utils_mount_spec.c b/src/utils/cutils/utils_mount_spec.c
|
||||
index a262a249..d8f64c81 100644
|
||||
--- a/src/utils/cutils/utils_mount_spec.c
|
||||
+++ b/src/utils/cutils/utils_mount_spec.c
|
||||
@@ -31,8 +31,8 @@
|
||||
#include "path.h"
|
||||
|
||||
#define CACHE_ERRMSG_LEN 512
|
||||
-#define CACHE_ERRMSG(errmsg, fmt, args...) \
|
||||
- do { \
|
||||
+#define CACHE_ERRMSG(errmsg, fmt, args...) \
|
||||
+ do { \
|
||||
(void)snprintf(errmsg, CACHE_ERRMSG_LEN, fmt, ##args); \
|
||||
} while (0)
|
||||
|
||||
@@ -49,8 +49,8 @@ static int parse_mount_item_type(const char *value, char *mount_str, mount_spec
|
||||
}
|
||||
|
||||
#ifdef ENABLE_OCI_IMAGE
|
||||
- if (strcmp(value, MOUNT_TYPE_SQUASHFS) && strcmp(value, MOUNT_TYPE_BIND) &&
|
||||
- strcmp(value, MOUNT_TYPE_VOLUME) && strcmp(value, MOUNT_TYPE_TMPFS)) {
|
||||
+ if (strcmp(value, MOUNT_TYPE_SQUASHFS) != 0 && strcmp(value, MOUNT_TYPE_BIND) != 0 &&
|
||||
+ strcmp(value, MOUNT_TYPE_VOLUME) != 0 && strcmp(value, MOUNT_TYPE_TMPFS) != 0) {
|
||||
CACHE_ERRMSG(errmsg, "Invalid mount specification '%s'.Type must be one of squashfs/bind/volume/tmpfs",
|
||||
mount_str);
|
||||
#else
|
||||
@@ -67,7 +67,7 @@ static int parse_mount_item_type(const char *value, char *mount_str, mount_spec
|
||||
|
||||
static int parse_mount_item_src(const char *value, char *mount_str, mount_spec *m, char *errmsg)
|
||||
{
|
||||
- char srcpath[PATH_MAX] = {0};
|
||||
+ char srcpath[PATH_MAX] = { 0 };
|
||||
|
||||
/* If value of source is NULL, ignore it */
|
||||
if (value == NULL) {
|
||||
@@ -88,7 +88,8 @@ static int parse_mount_item_src(const char *value, char *mount_str, mount_spec *
|
||||
|
||||
if (value[0] == '/') {
|
||||
if (!util_clean_path(value, srcpath, sizeof(srcpath))) {
|
||||
- CACHE_ERRMSG(errmsg, "Invalid mount specification '%s'.Can't translate source path to clean path", mount_str);
|
||||
+ CACHE_ERRMSG(errmsg, "Invalid mount specification '%s'.Can't translate source path to clean path",
|
||||
+ mount_str);
|
||||
return EINVALIDARGS;
|
||||
}
|
||||
m->source = util_strdup_s(srcpath);
|
||||
@@ -119,7 +120,8 @@ static int parse_mount_item_dst(const char *value, char *mount_str, mount_spec *
|
||||
}
|
||||
|
||||
if (!util_clean_path(value, dstpath, sizeof(dstpath))) {
|
||||
- CACHE_ERRMSG(errmsg, "Invalid mount specification '%s'.Can't translate destination path to clean path", mount_str);
|
||||
+ CACHE_ERRMSG(errmsg, "Invalid mount specification '%s'.Can't translate destination path to clean path",
|
||||
+ mount_str);
|
||||
return EINVALIDARGS;
|
||||
}
|
||||
|
||||
@@ -306,7 +308,7 @@ static int parse_mount_item_nocopy(const char *value, char *mount_str, mount_spe
|
||||
|
||||
static bool exist_readonly_mode(char *mount_str)
|
||||
{
|
||||
- char tmp_mount_str[PATH_MAX] = {0};
|
||||
+ char tmp_mount_str[PATH_MAX] = { 0 };
|
||||
int sret = 0;
|
||||
|
||||
// add "," at start and end of mount string to simplize check
|
||||
@@ -332,25 +334,26 @@ static bool valid_mount_spec_mode(char *mount_str, mount_spec *m, char *errmsg)
|
||||
return false;
|
||||
}
|
||||
if (exist_readonly_mode(mount_str) && m->source == NULL) {
|
||||
- CACHE_ERRMSG(errmsg, "Invalid mount specification '%s'.Readonly mode must not be specified "
|
||||
- "for anonymous volume", mount_str);
|
||||
+ CACHE_ERRMSG(errmsg,
|
||||
+ "Invalid mount specification '%s'.Readonly mode must not be specified for anonymous volume",
|
||||
+ mount_str);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (strcmp(m->type, MOUNT_TYPE_BIND) == 0 && m->volume_options != NULL) {
|
||||
- CACHE_ERRMSG(errmsg, "Invalid mount specification '%s'.nocopy must not be specified for type %s",
|
||||
- mount_str, m->type);
|
||||
+ CACHE_ERRMSG(errmsg, "Invalid mount specification '%s'.nocopy must not be specified for type %s", mount_str,
|
||||
+ m->type);
|
||||
return false;
|
||||
}
|
||||
if (strcmp(m->type, MOUNT_TYPE_TMPFS) == 0) {
|
||||
if (m->volume_options != NULL) {
|
||||
- CACHE_ERRMSG(errmsg, "Invalid mount specification '%s'.Cannot mix volume options with type %s",
|
||||
- mount_str, m->type);
|
||||
+ CACHE_ERRMSG(errmsg, "Invalid mount specification '%s'.Cannot mix volume options with type %s", mount_str,
|
||||
+ m->type);
|
||||
return false;
|
||||
}
|
||||
if (m->bind_options != NULL) {
|
||||
- CACHE_ERRMSG(errmsg, "Invalid mount specification '%s'.Cannot mix bind options with type %s",
|
||||
- mount_str, m->type);
|
||||
+ CACHE_ERRMSG(errmsg, "Invalid mount specification '%s'.Cannot mix bind options with type %s", mount_str,
|
||||
+ m->type);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -415,7 +418,6 @@ static int check_mount_spec(char *mount_str, mount_spec *m, char *errmsg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
-
|
||||
static int parse_mounts_item(const char *mntkey, const char *value, char *mount_str, mount_spec *m, char *errmsg)
|
||||
{
|
||||
if (util_valid_key_type(mntkey)) {
|
||||
@@ -452,7 +454,7 @@ int util_parse_mount_spec(char *mount_str, mount_spec **spec, char **errmsg_out)
|
||||
size_t items_len = 0;
|
||||
char **items = NULL;
|
||||
char **key_val = NULL;
|
||||
- char errmsg[CACHE_ERRMSG_LEN] = {0};
|
||||
+ char errmsg[CACHE_ERRMSG_LEN] = { 0 };
|
||||
|
||||
if (mount_str == NULL) {
|
||||
CACHE_ERRMSG(errmsg, "Invalid mount specification: can't be empty");
|
||||
@@ -528,7 +530,7 @@ bool util_valid_mount_spec(const char *mount_str, char **errmsg)
|
||||
mount_spec *m = NULL;
|
||||
|
||||
// if parse success, it's valid
|
||||
- ret = util_parse_mount_spec((char*)mount_str, &m, errmsg);
|
||||
+ ret = util_parse_mount_spec((char *)mount_str, &m, errmsg);
|
||||
if (ret != 0) {
|
||||
goto out;
|
||||
}
|
||||
@@ -538,4 +540,3 @@ out:
|
||||
|
||||
return ret ? false : true;
|
||||
}
|
||||
-
|
||||
diff --git a/src/utils/cutils/utils_string.c b/src/utils/cutils/utils_string.c
|
||||
index 7e504326..8c9b2eea 100644
|
||||
--- a/src/utils/cutils/utils_string.c
|
||||
+++ b/src/utils/cutils/utils_string.c
|
||||
@@ -795,7 +795,7 @@ bool util_has_prefix(const char *str, const char *prefix)
|
||||
return false;
|
||||
}
|
||||
|
||||
- if (strncmp(str, prefix, strlen(prefix))) {
|
||||
+ if (strncmp(str, prefix, strlen(prefix)) != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -817,7 +817,7 @@ bool util_has_suffix(const char *str, const char *suffix)
|
||||
return false;
|
||||
}
|
||||
|
||||
- if (strcmp(str + str_len - suffix_len, suffix)) {
|
||||
+ if (strcmp(str + str_len - suffix_len, suffix) != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
diff --git a/src/utils/cutils/utils_timestamp.c b/src/utils/cutils/utils_timestamp.c
|
||||
index 53ca7a95..ef695d3e 100644
|
||||
--- a/src/utils/cutils/utils_timestamp.c
|
||||
+++ b/src/utils/cutils/utils_timestamp.c
|
||||
@@ -189,8 +189,7 @@ bool get_time_buffer_help(const types_timestamp_t *timestamp, char *timebuffer,
|
||||
if (tm_zone >= 0) {
|
||||
nret = snprintf(timebuffer + strlen(timebuffer), tmp_size, ".%09d+%02d:00", nanos, tm_zone);
|
||||
} else {
|
||||
- nret = snprintf(timebuffer + strlen(timebuffer), tmp_size, ".%09d-%02d:00", nanos,
|
||||
- -tm_zone);
|
||||
+ nret = snprintf(timebuffer + strlen(timebuffer), tmp_size, ".%09d-%02d:00", nanos, -tm_zone);
|
||||
}
|
||||
|
||||
out:
|
||||
@@ -524,7 +523,7 @@ static char *tm_get_zp(const char *tmstr)
|
||||
return zp;
|
||||
}
|
||||
|
||||
-static inline bool hasnil(const char *str, struct tm *tm, int32_t *nanos, struct types_timezone *tz)
|
||||
+static inline bool hasnil(const char *str, const struct tm *tm, const int32_t *nanos, const struct types_timezone *tz)
|
||||
{
|
||||
if (str == NULL || tm == NULL || nanos == NULL || tz == NULL) {
|
||||
return true;
|
||||
@@ -656,9 +655,9 @@ int64_t util_time_seconds_since(const char *in)
|
||||
|
||||
if (result > 0) {
|
||||
return result;
|
||||
- } else {
|
||||
- return 0;
|
||||
}
|
||||
+
|
||||
+ return 0;
|
||||
}
|
||||
|
||||
struct time_human_duration_rule_t {
|
||||
@@ -1066,4 +1065,4 @@ int util_time_str_to_nanoseconds(const char *value, int64_t *nanoseconds)
|
||||
out:
|
||||
free(num_str);
|
||||
return ret;
|
||||
-}
|
||||
\ No newline at end of file
|
||||
+}
|
||||
--
|
||||
2.20.1
|
||||
|
||||
@ -1,226 +0,0 @@
|
||||
From 92ceff55c726abfabdc6e7f54d4e67b0c6c24196 Mon Sep 17 00:00:00 2001
|
||||
From: wujing <wujing50@huawei.com>
|
||||
Date: Tue, 18 Jan 2022 19:59:39 +0800
|
||||
Subject: [PATCH 10/16] clean the gRPC client module code
|
||||
|
||||
Signed-off-by: wujing <wujing50@huawei.com>
|
||||
---
|
||||
src/client/connect/grpc/client_base.h | 4 +-
|
||||
.../connect/grpc/grpc_containers_client.cc | 2 +-
|
||||
src/client/connect/grpc/grpc_images_client.cc | 37 +++++++++++--------
|
||||
.../connect/grpc/grpc_volumes_client.cc | 27 +++++++-------
|
||||
4 files changed, 38 insertions(+), 32 deletions(-)
|
||||
|
||||
diff --git a/src/client/connect/grpc/client_base.h b/src/client/connect/grpc/client_base.h
|
||||
index f37bf471..dbe130cd 100644
|
||||
--- a/src/client/connect/grpc/client_base.h
|
||||
+++ b/src/client/connect/grpc/client_base.h
|
||||
@@ -41,7 +41,7 @@ class ClientBase {
|
||||
public:
|
||||
explicit ClientBase(void *args)
|
||||
{
|
||||
- client_connect_config_t *arguments = reinterpret_cast<client_connect_config_t *>(args);
|
||||
+ auto *arguments = reinterpret_cast<client_connect_config_t *>(args);
|
||||
|
||||
std::string socket_address = arguments->socket;
|
||||
const std::string tcp_prefix = "tcp://";
|
||||
@@ -207,7 +207,7 @@ protected:
|
||||
|
||||
std::unique_ptr<sTB> stub_;
|
||||
std::string m_tlsMode { ClientBaseConstants::TLS_OFF };
|
||||
- std::string m_certFile { "" };
|
||||
+ std::string m_certFile;
|
||||
|
||||
unsigned int deadline;
|
||||
};
|
||||
diff --git a/src/client/connect/grpc/grpc_containers_client.cc b/src/client/connect/grpc/grpc_containers_client.cc
|
||||
index 822edd8f..ebe71df9 100644
|
||||
--- a/src/client/connect/grpc/grpc_containers_client.cc
|
||||
+++ b/src/client/connect/grpc/grpc_containers_client.cc
|
||||
@@ -2138,7 +2138,7 @@ public:
|
||||
// Set common name from cert.perm
|
||||
char common_name_value[ClientBaseConstants::COMMON_NAME_LEN] = { 0 };
|
||||
int ret = get_common_name_from_tls_cert(m_certFile.c_str(), common_name_value,
|
||||
- ClientBaseConstants::COMMON_NAME_LEN);
|
||||
+ ClientBaseConstants::COMMON_NAME_LEN);
|
||||
if (ret != 0) {
|
||||
ERROR("Failed to get common name in: %s", m_certFile.c_str());
|
||||
return -1;
|
||||
diff --git a/src/client/connect/grpc/grpc_images_client.cc b/src/client/connect/grpc/grpc_images_client.cc
|
||||
index 1bc12e69..50265e04 100644
|
||||
--- a/src/client/connect/grpc/grpc_images_client.cc
|
||||
+++ b/src/client/connect/grpc/grpc_images_client.cc
|
||||
@@ -81,8 +81,8 @@ public:
|
||||
for (i = 0; i < num; i++) {
|
||||
const Image &image = gresponse->images(i);
|
||||
if (image.has_target()) {
|
||||
- const char *media_type =
|
||||
- !image.target().media_type().empty() ? image.target().media_type().c_str() : "-";
|
||||
+ const char *media_type = !image.target().media_type().empty() ? image.target().media_type().c_str() :
|
||||
+ "-";
|
||||
images_list[i].type = util_strdup_s(media_type);
|
||||
const char *digest = !image.target().digest().empty() ? image.target().digest().c_str() : "-";
|
||||
images_list[i].digest = util_strdup_s(digest);
|
||||
@@ -336,9 +336,9 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
-class ImagesPull : public
|
||||
- ClientBase<runtime::v1alpha2::ImageService, runtime::v1alpha2::ImageService::Stub, isula_pull_request,
|
||||
- runtime::v1alpha2::PullImageRequest, isula_pull_response, runtime::v1alpha2::PullImageResponse> {
|
||||
+class ImagesPull : public ClientBase<runtime::v1alpha2::ImageService, runtime::v1alpha2::ImageService::Stub,
|
||||
+ isula_pull_request, runtime::v1alpha2::PullImageRequest, isula_pull_response,
|
||||
+ runtime::v1alpha2::PullImageResponse> {
|
||||
public:
|
||||
explicit ImagesPull(void *args)
|
||||
: ClientBase(args)
|
||||
@@ -346,14 +346,15 @@ public:
|
||||
}
|
||||
~ImagesPull() = default;
|
||||
|
||||
- auto request_to_grpc(const isula_pull_request *request, runtime::v1alpha2::PullImageRequest *grequest) -> int override
|
||||
+ auto request_to_grpc(const isula_pull_request *request, runtime::v1alpha2::PullImageRequest *grequest)
|
||||
+ -> int override
|
||||
{
|
||||
if (request == nullptr) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (request->image_name != nullptr) {
|
||||
- runtime::v1alpha2::ImageSpec *image_spec = new (std::nothrow) runtime::v1alpha2::ImageSpec;
|
||||
+ auto *image_spec = new (std::nothrow) runtime::v1alpha2::ImageSpec;
|
||||
if (image_spec == nullptr) {
|
||||
return -1;
|
||||
}
|
||||
@@ -364,7 +365,8 @@ public:
|
||||
return 0;
|
||||
}
|
||||
|
||||
- auto response_from_grpc(runtime::v1alpha2::PullImageResponse *gresponse, isula_pull_response *response) -> int override
|
||||
+ auto response_from_grpc(runtime::v1alpha2::PullImageResponse *gresponse, isula_pull_response *response)
|
||||
+ -> int override
|
||||
{
|
||||
if (!gresponse->image_ref().empty()) {
|
||||
response->image_ref = util_strdup_s(gresponse->image_ref().c_str());
|
||||
@@ -437,17 +439,20 @@ public:
|
||||
return 0;
|
||||
}
|
||||
|
||||
- auto grpc_call(ClientContext *context, const InspectImageRequest &req, InspectImageResponse *reply) -> Status override
|
||||
+ auto grpc_call(ClientContext *context, const InspectImageRequest &req, InspectImageResponse *reply)
|
||||
+ -> Status override
|
||||
{
|
||||
return stub_->Inspect(context, req, reply);
|
||||
}
|
||||
};
|
||||
|
||||
-class Login : public
|
||||
- ClientBase<ImagesService, ImagesService::Stub, isula_login_request, LoginRequest,
|
||||
+class Login : public ClientBase<ImagesService, ImagesService::Stub, isula_login_request, LoginRequest,
|
||||
isula_login_response, LoginResponse> {
|
||||
public:
|
||||
- explicit Login(void *args) : ClientBase(args) {}
|
||||
+ explicit Login(void *args)
|
||||
+ : ClientBase(args)
|
||||
+ {
|
||||
+ }
|
||||
~Login() = default;
|
||||
|
||||
auto request_to_grpc(const isula_login_request *request, LoginRequest *grequest) -> int override
|
||||
@@ -511,11 +516,13 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
-class Logout : public
|
||||
- ClientBase<ImagesService, ImagesService::Stub, isula_logout_request, LogoutRequest,
|
||||
+class Logout : public ClientBase<ImagesService, ImagesService::Stub, isula_logout_request, LogoutRequest,
|
||||
isula_logout_response, LogoutResponse> {
|
||||
public:
|
||||
- explicit Logout(void *args) : ClientBase(args) {}
|
||||
+ explicit Logout(void *args)
|
||||
+ : ClientBase(args)
|
||||
+ {
|
||||
+ }
|
||||
~Logout() = default;
|
||||
|
||||
auto request_to_grpc(const isula_logout_request *request, LogoutRequest *grequest) -> int override
|
||||
diff --git a/src/client/connect/grpc/grpc_volumes_client.cc b/src/client/connect/grpc/grpc_volumes_client.cc
|
||||
index d8eb74b2..5d55b8c8 100644
|
||||
--- a/src/client/connect/grpc/grpc_volumes_client.cc
|
||||
+++ b/src/client/connect/grpc/grpc_volumes_client.cc
|
||||
@@ -27,10 +27,10 @@ using grpc::ClientContext;
|
||||
using grpc::Status;
|
||||
|
||||
class VolumeList : public ClientBase<VolumeService, VolumeService::Stub, isula_list_volume_request, ListVolumeRequest,
|
||||
- isula_list_volume_response, ListVolumeResponse> {
|
||||
+ isula_list_volume_response, ListVolumeResponse> {
|
||||
public:
|
||||
explicit VolumeList(void *args)
|
||||
- : ClientBase(args)
|
||||
+ : ClientBase(args)
|
||||
{
|
||||
}
|
||||
~VolumeList() = default;
|
||||
@@ -57,8 +57,8 @@ public:
|
||||
response->cc = ISULAD_ERR_MEMOUT;
|
||||
return -1;
|
||||
}
|
||||
- auto volumes = static_cast<struct isula_volume_info *>(
|
||||
- util_common_calloc_s(sizeof(struct isula_volume_info) * static_cast<size_t>(num)));
|
||||
+ auto *volumes = static_cast<struct isula_volume_info *>(
|
||||
+ util_smart_calloc_s(sizeof(struct isula_volume_info), static_cast<size_t>(num)));
|
||||
if (volumes == nullptr) {
|
||||
ERROR("out of memory");
|
||||
response->cc = ISULAD_ERR_MEMOUT;
|
||||
@@ -89,12 +89,11 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
-class VolumeRemove : public
|
||||
- ClientBase<VolumeService, VolumeService::Stub, isula_remove_volume_request, RemoveVolumeRequest,
|
||||
- isula_remove_volume_response, RemoveVolumeResponse> {
|
||||
+class VolumeRemove : public ClientBase<VolumeService, VolumeService::Stub, isula_remove_volume_request,
|
||||
+ RemoveVolumeRequest, isula_remove_volume_response, RemoveVolumeResponse> {
|
||||
public:
|
||||
explicit VolumeRemove(void *args)
|
||||
- : ClientBase(args)
|
||||
+ : ClientBase(args)
|
||||
{
|
||||
}
|
||||
~VolumeRemove() = default;
|
||||
@@ -135,18 +134,18 @@ public:
|
||||
return 0;
|
||||
}
|
||||
|
||||
- auto grpc_call(ClientContext *context, const RemoveVolumeRequest &req, RemoveVolumeResponse *reply) -> Status override
|
||||
+ auto grpc_call(ClientContext *context, const RemoveVolumeRequest &req, RemoveVolumeResponse *reply)
|
||||
+ -> Status override
|
||||
{
|
||||
return stub_->Remove(context, req, reply);
|
||||
}
|
||||
};
|
||||
|
||||
-class VolumePrune : public
|
||||
- ClientBase<VolumeService, VolumeService::Stub, isula_prune_volume_request, PruneVolumeRequest,
|
||||
- isula_prune_volume_response, PruneVolumeResponse> {
|
||||
+class VolumePrune : public ClientBase<VolumeService, VolumeService::Stub, isula_prune_volume_request,
|
||||
+ PruneVolumeRequest, isula_prune_volume_response, PruneVolumeResponse> {
|
||||
public:
|
||||
explicit VolumePrune(void *args)
|
||||
- : ClientBase(args)
|
||||
+ : ClientBase(args)
|
||||
{
|
||||
}
|
||||
~VolumePrune() = default;
|
||||
@@ -158,7 +157,7 @@ public:
|
||||
auto size = gresponse->volumes_size();
|
||||
if (size != 0) {
|
||||
response->volumes = static_cast<char **>(util_common_calloc_s(sizeof(char *) * size));
|
||||
- if (response->volumes == NULL) {
|
||||
+ if (response->volumes == nullptr) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
--
|
||||
2.20.1
|
||||
|
||||
@ -1,238 +0,0 @@
|
||||
From 3e2793ee0124dff55464ad78d34ab2288ab7c382 Mon Sep 17 00:00:00 2001
|
||||
From: wujing <wujing50@huawei.com>
|
||||
Date: Mon, 28 Feb 2022 19:40:45 +0800
|
||||
Subject: [PATCH 11/16] remove redundant code
|
||||
|
||||
Signed-off-by: wujing <wujing50@huawei.com>
|
||||
---
|
||||
.../connect/grpc/grpc_volumes_client.cc | 16 +++++++-------
|
||||
src/client/connect/protocol_type.c | 22 +------------------
|
||||
2 files changed, 9 insertions(+), 29 deletions(-)
|
||||
|
||||
diff --git a/src/client/connect/grpc/grpc_volumes_client.cc b/src/client/connect/grpc/grpc_volumes_client.cc
|
||||
index 5d55b8c8..902e8a13 100644
|
||||
--- a/src/client/connect/grpc/grpc_volumes_client.cc
|
||||
+++ b/src/client/connect/grpc/grpc_volumes_client.cc
|
||||
@@ -27,10 +27,10 @@ using grpc::ClientContext;
|
||||
using grpc::Status;
|
||||
|
||||
class VolumeList : public ClientBase<VolumeService, VolumeService::Stub, isula_list_volume_request, ListVolumeRequest,
|
||||
- isula_list_volume_response, ListVolumeResponse> {
|
||||
+ isula_list_volume_response, ListVolumeResponse> {
|
||||
public:
|
||||
explicit VolumeList(void *args)
|
||||
- : ClientBase(args)
|
||||
+ : ClientBase(args)
|
||||
{
|
||||
}
|
||||
~VolumeList() = default;
|
||||
@@ -58,7 +58,7 @@ public:
|
||||
return -1;
|
||||
}
|
||||
auto *volumes = static_cast<struct isula_volume_info *>(
|
||||
- util_smart_calloc_s(sizeof(struct isula_volume_info), static_cast<size_t>(num)));
|
||||
+ util_smart_calloc_s(sizeof(struct isula_volume_info), static_cast<size_t>(num)));
|
||||
if (volumes == nullptr) {
|
||||
ERROR("out of memory");
|
||||
response->cc = ISULAD_ERR_MEMOUT;
|
||||
@@ -90,10 +90,10 @@ public:
|
||||
};
|
||||
|
||||
class VolumeRemove : public ClientBase<VolumeService, VolumeService::Stub, isula_remove_volume_request,
|
||||
- RemoveVolumeRequest, isula_remove_volume_response, RemoveVolumeResponse> {
|
||||
+ RemoveVolumeRequest, isula_remove_volume_response, RemoveVolumeResponse> {
|
||||
public:
|
||||
explicit VolumeRemove(void *args)
|
||||
- : ClientBase(args)
|
||||
+ : ClientBase(args)
|
||||
{
|
||||
}
|
||||
~VolumeRemove() = default;
|
||||
@@ -135,17 +135,17 @@ public:
|
||||
}
|
||||
|
||||
auto grpc_call(ClientContext *context, const RemoveVolumeRequest &req, RemoveVolumeResponse *reply)
|
||||
- -> Status override
|
||||
+ -> Status override
|
||||
{
|
||||
return stub_->Remove(context, req, reply);
|
||||
}
|
||||
};
|
||||
|
||||
class VolumePrune : public ClientBase<VolumeService, VolumeService::Stub, isula_prune_volume_request,
|
||||
- PruneVolumeRequest, isula_prune_volume_response, PruneVolumeResponse> {
|
||||
+ PruneVolumeRequest, isula_prune_volume_response, PruneVolumeResponse> {
|
||||
public:
|
||||
explicit VolumePrune(void *args)
|
||||
- : ClientBase(args)
|
||||
+ : ClientBase(args)
|
||||
{
|
||||
}
|
||||
~VolumePrune() = default;
|
||||
diff --git a/src/client/connect/protocol_type.c b/src/client/connect/protocol_type.c
|
||||
index 3e5dafb1..af582abf 100644
|
||||
--- a/src/client/connect/protocol_type.c
|
||||
+++ b/src/client/connect/protocol_type.c
|
||||
@@ -916,7 +916,6 @@ void isula_create_image_request_free(struct isula_create_image_request *request)
|
||||
request->image_info.digest = NULL;
|
||||
|
||||
free(request);
|
||||
- return;
|
||||
}
|
||||
|
||||
/* isula create image response free */
|
||||
@@ -939,7 +938,6 @@ void isula_create_image_response_free(struct isula_create_image_response *respon
|
||||
response->image_info.digest = NULL;
|
||||
|
||||
free(response);
|
||||
- return;
|
||||
}
|
||||
|
||||
/* isula images list free */
|
||||
@@ -959,7 +957,6 @@ void isula_images_list_free(size_t images_num, struct isula_image_info *images_l
|
||||
}
|
||||
|
||||
free(images_list);
|
||||
- return;
|
||||
}
|
||||
|
||||
/* isula list images request free */
|
||||
@@ -970,7 +967,6 @@ void isula_list_images_request_free(struct isula_list_images_request *request)
|
||||
}
|
||||
|
||||
free(request);
|
||||
- return;
|
||||
}
|
||||
|
||||
/* isula list images response free */
|
||||
@@ -1000,7 +996,6 @@ void isula_rmi_request_free(struct isula_rmi_request *request)
|
||||
request->image_name = NULL;
|
||||
|
||||
free(request);
|
||||
- return;
|
||||
}
|
||||
|
||||
/* isula rmi response free */
|
||||
@@ -1014,7 +1009,6 @@ void isula_rmi_response_free(struct isula_rmi_response *response)
|
||||
response->errmsg = NULL;
|
||||
|
||||
free(response);
|
||||
- return;
|
||||
}
|
||||
|
||||
/* isula tag request free */
|
||||
@@ -1030,7 +1024,6 @@ void isula_tag_request_free(struct isula_tag_request *request)
|
||||
request->dest_name = NULL;
|
||||
|
||||
free(request);
|
||||
- return;
|
||||
}
|
||||
|
||||
/* isula tag response free */
|
||||
@@ -1044,7 +1037,6 @@ void isula_tag_response_free(struct isula_tag_response *response)
|
||||
response->errmsg = NULL;
|
||||
|
||||
free(response);
|
||||
- return;
|
||||
}
|
||||
|
||||
/* isula pull response free */
|
||||
@@ -1058,7 +1050,6 @@ void isula_pull_request_free(struct isula_pull_request *request)
|
||||
request->image_name = NULL;
|
||||
|
||||
free(request);
|
||||
- return;
|
||||
}
|
||||
|
||||
/* isula pull response free */
|
||||
@@ -1074,7 +1065,6 @@ void isula_pull_response_free(struct isula_pull_response *response)
|
||||
free(response->errmsg);
|
||||
response->errmsg = NULL;
|
||||
free(response);
|
||||
- return;
|
||||
}
|
||||
|
||||
/* isula import request free */
|
||||
@@ -1091,7 +1081,6 @@ void isula_import_request_free(struct isula_import_request *request)
|
||||
request->tag = NULL;
|
||||
|
||||
free(request);
|
||||
- return;
|
||||
}
|
||||
|
||||
/* isula import response free */
|
||||
@@ -1108,7 +1097,6 @@ void isula_import_response_free(struct isula_import_response *response)
|
||||
response->errmsg = NULL;
|
||||
|
||||
free(response);
|
||||
- return;
|
||||
}
|
||||
|
||||
/* isula load request free */
|
||||
@@ -1128,7 +1116,6 @@ void isula_load_request_free(struct isula_load_request *request)
|
||||
request->tag = NULL;
|
||||
|
||||
free(request);
|
||||
- return;
|
||||
}
|
||||
|
||||
/* isula load response free */
|
||||
@@ -1142,7 +1129,6 @@ void isula_load_response_free(struct isula_load_response *response)
|
||||
response->errmsg = NULL;
|
||||
|
||||
free(response);
|
||||
- return;
|
||||
}
|
||||
|
||||
/* isula login response free */
|
||||
@@ -1156,7 +1142,6 @@ void isula_login_response_free(struct isula_login_response *response)
|
||||
response->errmsg = NULL;
|
||||
|
||||
free(response);
|
||||
- return;
|
||||
}
|
||||
|
||||
/* isula logout response free */
|
||||
@@ -1170,7 +1155,6 @@ void isula_logout_response_free(struct isula_logout_response *response)
|
||||
response->errmsg = NULL;
|
||||
|
||||
free(response);
|
||||
- return;
|
||||
}
|
||||
|
||||
/* isula export request free */
|
||||
@@ -1331,8 +1315,6 @@ void isula_volume_list_free(size_t volumes_len, struct isula_volume_info *volume
|
||||
free(volume->name);
|
||||
}
|
||||
free(volumes);
|
||||
-
|
||||
- return;
|
||||
}
|
||||
|
||||
void isula_list_volume_response_free(struct isula_list_volume_response *response)
|
||||
@@ -1349,7 +1331,6 @@ void isula_list_volume_response_free(struct isula_list_volume_response *response
|
||||
response->errmsg = NULL;
|
||||
|
||||
free(response);
|
||||
- return;
|
||||
}
|
||||
|
||||
void isula_remove_volume_response_free(struct isula_remove_volume_response *response)
|
||||
@@ -1362,7 +1343,6 @@ void isula_remove_volume_response_free(struct isula_remove_volume_response *resp
|
||||
response->errmsg = NULL;
|
||||
|
||||
free(response);
|
||||
- return;
|
||||
}
|
||||
|
||||
void isula_prune_volume_response_free(struct isula_prune_volume_response *response)
|
||||
@@ -1386,5 +1366,5 @@ void isula_prune_volume_response_free(struct isula_prune_volume_response *respon
|
||||
response->errmsg = NULL;
|
||||
|
||||
free(response);
|
||||
- return;
|
||||
}
|
||||
+
|
||||
--
|
||||
2.20.1
|
||||
|
||||
@ -1,501 +0,0 @@
|
||||
From 067caad399deb58eac9aefee85011ab9aff32f54 Mon Sep 17 00:00:00 2001
|
||||
From: wujing <wujing50@huawei.com>
|
||||
Date: Mon, 28 Feb 2022 20:30:08 +0800
|
||||
Subject: [PATCH 12/16] fix coding irregularities of entry module
|
||||
|
||||
Signed-off-by: wujing <wujing50@huawei.com>
|
||||
---
|
||||
.../connect/grpc/grpc_containers_service.cc | 31 +++++++++----------
|
||||
.../connect/grpc/grpc_containers_service.h | 3 +-
|
||||
.../entry/connect/grpc/grpc_images_service.cc | 24 ++++++--------
|
||||
.../entry/connect/grpc/grpc_images_service.h | 3 +-
|
||||
.../connect/grpc/grpc_server_tls_auth.cc | 5 ++-
|
||||
.../entry/connect/grpc/grpc_server_tls_auth.h | 5 ++-
|
||||
.../connect/grpc/grpc_volumes_service.cc | 12 +++----
|
||||
src/daemon/entry/cri/cri_constants.cc | 4 +--
|
||||
src/daemon/entry/cri/errors.cc | 2 +-
|
||||
src/daemon/entry/cri/errors.h | 2 +-
|
||||
src/daemon/entry/cri/network_plugin.cc | 9 +++---
|
||||
src/daemon/entry/cri/request_cache.cc | 2 +-
|
||||
.../entry/cri/websocket/service/exec_serve.cc | 2 +-
|
||||
.../entry/cri/websocket/service/ws_server.h | 1 +
|
||||
14 files changed, 48 insertions(+), 57 deletions(-)
|
||||
|
||||
diff --git a/src/daemon/entry/connect/grpc/grpc_containers_service.cc b/src/daemon/entry/connect/grpc/grpc_containers_service.cc
|
||||
index 54529998..f3066af4 100644
|
||||
--- a/src/daemon/entry/connect/grpc/grpc_containers_service.cc
|
||||
+++ b/src/daemon/entry/connect/grpc/grpc_containers_service.cc
|
||||
@@ -99,8 +99,8 @@ bool grpc_add_initial_metadata(void *context, const char *header, const char *va
|
||||
|
||||
bool grpc_event_write_function(void *writer, void *data)
|
||||
{
|
||||
- struct isulad_events_format *event = (struct isulad_events_format *)data;
|
||||
- ServerWriter<Event> *gwriter = (ServerWriter<Event> *)writer;
|
||||
+ auto *event = (struct isulad_events_format *)data;
|
||||
+ auto *gwriter = (ServerWriter<Event> *)writer;
|
||||
Event gevent;
|
||||
if (event_to_grpc(event, &gevent) != 0) {
|
||||
return false;
|
||||
@@ -110,8 +110,8 @@ bool grpc_event_write_function(void *writer, void *data)
|
||||
|
||||
bool grpc_copy_from_container_write_function(void *writer, void *data)
|
||||
{
|
||||
- struct isulad_copy_from_container_response *copy = (struct isulad_copy_from_container_response *)data;
|
||||
- ServerWriter<CopyFromContainerResponse> *gwriter = (ServerWriter<CopyFromContainerResponse> *)writer;
|
||||
+ auto *copy = (struct isulad_copy_from_container_response *)data;
|
||||
+ auto *gwriter = (ServerWriter<CopyFromContainerResponse> *)writer;
|
||||
CopyFromContainerResponse gcopy;
|
||||
copy_from_container_response_to_grpc(copy, &gcopy);
|
||||
return gwriter->Write(gcopy);
|
||||
@@ -137,9 +137,8 @@ static bool copy_to_container_data_from_grpc(struct isulad_copy_to_container_dat
|
||||
|
||||
bool grpc_copy_to_container_read_function(void *reader, void *data)
|
||||
{
|
||||
- struct isulad_copy_to_container_data *copy = (struct isulad_copy_to_container_data *)data;
|
||||
- ServerReaderWriter<CopyToContainerResponse, CopyToContainerRequest> *stream =
|
||||
- (ServerReaderWriter<CopyToContainerResponse, CopyToContainerRequest> *)reader;
|
||||
+ auto *copy = (struct isulad_copy_to_container_data *)data;
|
||||
+ auto *stream = (ServerReaderWriter<CopyToContainerResponse, CopyToContainerRequest> *)reader;
|
||||
CopyToContainerRequest gcopy;
|
||||
if (!stream->Read(&gcopy)) {
|
||||
return false;
|
||||
@@ -287,7 +286,7 @@ ssize_t WriteStartResponseToRemoteClient(void *context, const void *data, size_t
|
||||
return 0;
|
||||
}
|
||||
|
||||
- struct RemoteStartContext *ctx = (struct RemoteStartContext *)context;
|
||||
+ auto *ctx = (struct RemoteStartContext *)context;
|
||||
RemoteStartResponse response;
|
||||
if (ctx->isStdout) {
|
||||
response.set_stdout((char *)data, len);
|
||||
@@ -306,7 +305,7 @@ int grpc_start_stream_close(void *context, char **err)
|
||||
{
|
||||
int ret = 0;
|
||||
(void)err;
|
||||
- struct RemoteStartContext *ctx = (struct RemoteStartContext *)context;
|
||||
+ auto *ctx = (struct RemoteStartContext *)context;
|
||||
RemoteStartResponse finish_response;
|
||||
finish_response.set_finish(true);
|
||||
if (!ctx->stream->Write(finish_response)) {
|
||||
@@ -374,7 +373,7 @@ Status ContainerServiceImpl::RemoteStart(ServerContext *context,
|
||||
if (request.finish()) {
|
||||
break;
|
||||
}
|
||||
- std::string command = request.stdin();
|
||||
+ const std::string &command = request.stdin();
|
||||
if (write(read_pipe_fd[1], (void *)(command.c_str()), command.length()) < 0) {
|
||||
ERROR("sub write over!");
|
||||
break;
|
||||
@@ -593,7 +592,7 @@ ssize_t WriteExecStdoutResponseToRemoteClient(void *context, const void *data, s
|
||||
if (context == nullptr || data == nullptr || len == 0) {
|
||||
return 0;
|
||||
}
|
||||
- auto stream = static_cast<ServerReaderWriter<RemoteExecResponse, RemoteExecRequest> *>(context);
|
||||
+ auto *stream = static_cast<ServerReaderWriter<RemoteExecResponse, RemoteExecRequest> *>(context);
|
||||
RemoteExecResponse response;
|
||||
response.set_stdout((char *)data, len);
|
||||
if (!stream->Write(response)) {
|
||||
@@ -608,7 +607,7 @@ ssize_t WriteExecStderrResponseToRemoteClient(void *context, const void *data, s
|
||||
if (context == nullptr || data == nullptr || len == 0) {
|
||||
return 0;
|
||||
}
|
||||
- auto stream = static_cast<ServerReaderWriter<RemoteExecResponse, RemoteExecRequest> *>(context);
|
||||
+ auto *stream = static_cast<ServerReaderWriter<RemoteExecResponse, RemoteExecRequest> *>(context);
|
||||
RemoteExecResponse response;
|
||||
response.set_stderr((char *)data, len);
|
||||
if (!stream->Write(response)) {
|
||||
@@ -809,7 +808,7 @@ ssize_t WriteAttachResponseToRemoteClient(void *context, const void *data, size_
|
||||
if (context == nullptr || data == nullptr || len == 0) {
|
||||
return 0;
|
||||
}
|
||||
- struct AttachContext *ctx = (struct AttachContext *)context;
|
||||
+ auto *ctx = (struct AttachContext *)context;
|
||||
AttachResponse response;
|
||||
if (ctx->isStdout) {
|
||||
response.set_stdout((char *)data, len);
|
||||
@@ -828,7 +827,7 @@ int grpc_attach_stream_close(void *context, char **err)
|
||||
{
|
||||
int ret = 0;
|
||||
(void)err;
|
||||
- struct AttachContext *ctx = (struct AttachContext *)context;
|
||||
+ auto *ctx = (struct AttachContext *)context;
|
||||
AttachResponse finish_response;
|
||||
finish_response.set_finish(true);
|
||||
if (!ctx->stream->Write(finish_response)) {
|
||||
@@ -1372,8 +1371,8 @@ int ContainerServiceImpl::logs_request_from_grpc(const LogsRequest *grequest, st
|
||||
|
||||
bool grpc_logs_write_function(void *writer, void *data)
|
||||
{
|
||||
- logger_json_file *log = static_cast<logger_json_file *>(data);
|
||||
- ServerWriter<LogsResponse> *gwriter = static_cast<ServerWriter<LogsResponse> *>(writer);
|
||||
+ auto *log = static_cast<logger_json_file *>(data);
|
||||
+ auto *gwriter = static_cast<ServerWriter<LogsResponse> *>(writer);
|
||||
LogsResponse gresponse;
|
||||
log_to_grpc(log, &gresponse);
|
||||
return gwriter->Write(gresponse);
|
||||
diff --git a/src/daemon/entry/connect/grpc/grpc_containers_service.h b/src/daemon/entry/connect/grpc/grpc_containers_service.h
|
||||
index 4865c41e..d87e7e9f 100644
|
||||
--- a/src/daemon/entry/connect/grpc/grpc_containers_service.h
|
||||
+++ b/src/daemon/entry/connect/grpc/grpc_containers_service.h
|
||||
@@ -112,11 +112,12 @@ private:
|
||||
gresponse->set_cc(ISULAD_ERR_MEMOUT);
|
||||
return;
|
||||
}
|
||||
+
|
||||
gresponse->set_cc(response->cc);
|
||||
+
|
||||
if (response->errmsg != nullptr) {
|
||||
gresponse->set_errmsg(response->errmsg);
|
||||
}
|
||||
- return;
|
||||
}
|
||||
|
||||
int version_request_from_grpc(const VersionRequest *grequest, container_version_request **request);
|
||||
diff --git a/src/daemon/entry/connect/grpc/grpc_images_service.cc b/src/daemon/entry/connect/grpc/grpc_images_service.cc
|
||||
index 57a51ee0..dff07b39 100644
|
||||
--- a/src/daemon/entry/connect/grpc/grpc_images_service.cc
|
||||
+++ b/src/daemon/entry/connect/grpc/grpc_images_service.cc
|
||||
@@ -29,8 +29,7 @@ int ImagesServiceImpl::image_list_request_from_grpc(const ListImagesRequest *gre
|
||||
image_list_images_request **request)
|
||||
{
|
||||
size_t len = 0;
|
||||
- image_list_images_request *tmpreq =
|
||||
- (image_list_images_request *)util_common_calloc_s(sizeof(image_list_images_request));
|
||||
+ auto *tmpreq = (image_list_images_request *)util_common_calloc_s(sizeof(image_list_images_request));
|
||||
if (tmpreq == nullptr) {
|
||||
ERROR("Out of memory");
|
||||
return -1;
|
||||
@@ -63,7 +62,7 @@ int ImagesServiceImpl::image_list_request_from_grpc(const ListImagesRequest *gre
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
- for (auto &iter : grequest->filters()) {
|
||||
+ for (const auto &iter : grequest->filters()) {
|
||||
tmpreq->filters->values[tmpreq->filters->len] =
|
||||
(json_map_string_bool *)util_common_calloc_s(sizeof(json_map_string_bool));
|
||||
if (tmpreq->filters->values[tmpreq->filters->len] == nullptr) {
|
||||
@@ -71,7 +70,7 @@ int ImagesServiceImpl::image_list_request_from_grpc(const ListImagesRequest *gre
|
||||
goto cleanup;
|
||||
}
|
||||
if (append_json_map_string_bool(tmpreq->filters->values[tmpreq->filters->len],
|
||||
- iter.second.empty() ? "" : iter.second.c_str(), true)) {
|
||||
+ iter.second.empty() ? "" : iter.second.c_str(), true) != 0) {
|
||||
free(tmpreq->filters->values[tmpreq->filters->len]);
|
||||
tmpreq->filters->values[tmpreq->filters->len] = nullptr;
|
||||
ERROR("Append failed");
|
||||
@@ -129,15 +128,12 @@ void ImagesServiceImpl::image_list_response_to_grpc(image_list_images_response *
|
||||
target->set_size(response->images[i]->target->size);
|
||||
image->set_allocated_target(target);
|
||||
}
|
||||
-
|
||||
- return;
|
||||
}
|
||||
|
||||
int ImagesServiceImpl::image_remove_request_from_grpc(const DeleteImageRequest *grequest,
|
||||
image_delete_image_request **request)
|
||||
{
|
||||
- image_delete_image_request *tmpreq =
|
||||
- (image_delete_image_request *)util_common_calloc_s(sizeof(image_delete_image_request));
|
||||
+ auto *tmpreq = (image_delete_image_request *)util_common_calloc_s(sizeof(image_delete_image_request));
|
||||
if (tmpreq == nullptr) {
|
||||
ERROR("Out of memory");
|
||||
return -1;
|
||||
@@ -154,7 +150,7 @@ int ImagesServiceImpl::image_remove_request_from_grpc(const DeleteImageRequest *
|
||||
|
||||
int ImagesServiceImpl::image_tag_request_from_grpc(const TagImageRequest *grequest, image_tag_image_request **request)
|
||||
{
|
||||
- image_tag_image_request *tmpreq = (image_tag_image_request *)util_common_calloc_s(sizeof(image_tag_image_request));
|
||||
+ auto *tmpreq = (image_tag_image_request *)util_common_calloc_s(sizeof(image_tag_image_request));
|
||||
if (tmpreq == nullptr) {
|
||||
ERROR("Out of memory");
|
||||
return -1;
|
||||
@@ -193,8 +189,7 @@ int ImagesServiceImpl::image_import_request_from_grpc(const ImportRequest *grequ
|
||||
int ImagesServiceImpl::image_load_request_from_grpc(const LoadImageRequest *grequest,
|
||||
image_load_image_request **request)
|
||||
{
|
||||
- image_load_image_request *tmpreq =
|
||||
- (image_load_image_request *)util_common_calloc_s(sizeof(image_load_image_request));
|
||||
+ auto *tmpreq = (image_load_image_request *)util_common_calloc_s(sizeof(image_load_image_request));
|
||||
if (tmpreq == nullptr) {
|
||||
ERROR("Out of memory");
|
||||
return -1;
|
||||
@@ -216,7 +211,7 @@ int ImagesServiceImpl::image_load_request_from_grpc(const LoadImageRequest *greq
|
||||
|
||||
int ImagesServiceImpl::inspect_request_from_grpc(const InspectImageRequest *grequest, image_inspect_request **request)
|
||||
{
|
||||
- image_inspect_request *tmpreq = (image_inspect_request *)util_common_calloc_s(sizeof(image_inspect_request));
|
||||
+ auto *tmpreq = (image_inspect_request *)util_common_calloc_s(sizeof(image_inspect_request));
|
||||
if (tmpreq == nullptr) {
|
||||
ERROR("Out of memory");
|
||||
return -1;
|
||||
@@ -352,7 +347,6 @@ void ImagesServiceImpl::import_response_to_grpc(const image_import_response *res
|
||||
if (response->errmsg != nullptr) {
|
||||
gresponse->set_errmsg(response->errmsg);
|
||||
}
|
||||
- return;
|
||||
}
|
||||
|
||||
Status ImagesServiceImpl::Import(ServerContext *context, const ImportRequest *request, ImportResponse *reply)
|
||||
@@ -449,7 +443,7 @@ Status ImagesServiceImpl::Inspect(ServerContext *context, const InspectImageRequ
|
||||
|
||||
int ImagesServiceImpl::image_login_request_from_grpc(const LoginRequest *grequest, image_login_request **request)
|
||||
{
|
||||
- image_login_request *tmpreq = (image_login_request *)util_common_calloc_s(sizeof(image_login_request));
|
||||
+ auto *tmpreq = (image_login_request *)util_common_calloc_s(sizeof(image_login_request));
|
||||
if (tmpreq == nullptr) {
|
||||
ERROR("Out of memory");
|
||||
return -1;
|
||||
@@ -474,7 +468,7 @@ int ImagesServiceImpl::image_login_request_from_grpc(const LoginRequest *greques
|
||||
|
||||
int ImagesServiceImpl::image_logout_request_from_grpc(const LogoutRequest *grequest, image_logout_request **request)
|
||||
{
|
||||
- image_logout_request *tmpreq = (image_logout_request *)util_common_calloc_s(sizeof(image_logout_request));
|
||||
+ auto *tmpreq = (image_logout_request *)util_common_calloc_s(sizeof(image_logout_request));
|
||||
if (tmpreq == nullptr) {
|
||||
ERROR("Out of memory");
|
||||
return -1;
|
||||
diff --git a/src/daemon/entry/connect/grpc/grpc_images_service.h b/src/daemon/entry/connect/grpc/grpc_images_service.h
|
||||
index 92334b52..8ad486fd 100644
|
||||
--- a/src/daemon/entry/connect/grpc/grpc_images_service.h
|
||||
+++ b/src/daemon/entry/connect/grpc/grpc_images_service.h
|
||||
@@ -66,11 +66,12 @@ private:
|
||||
gresponse->set_cc(ISULAD_ERR_MEMOUT);
|
||||
return;
|
||||
}
|
||||
+
|
||||
gresponse->set_cc(response->cc);
|
||||
+
|
||||
if (response->errmsg != nullptr) {
|
||||
gresponse->set_errmsg(response->errmsg);
|
||||
}
|
||||
- return;
|
||||
}
|
||||
int image_list_request_from_grpc(const ListImagesRequest *grequest, image_list_images_request **request);
|
||||
|
||||
diff --git a/src/daemon/entry/connect/grpc/grpc_server_tls_auth.cc b/src/daemon/entry/connect/grpc/grpc_server_tls_auth.cc
|
||||
index 1bb1b928..6e958e23 100644
|
||||
--- a/src/daemon/entry/connect/grpc/grpc_server_tls_auth.cc
|
||||
+++ b/src/daemon/entry/connect/grpc/grpc_server_tls_auth.cc
|
||||
@@ -20,12 +20,12 @@
|
||||
|
||||
namespace AuthorizationPluginConfig {
|
||||
std::string auth_plugin = "";
|
||||
-};
|
||||
+} // namespace AuthorizationPluginConfig
|
||||
|
||||
namespace GrpcServerTlsAuth {
|
||||
Status auth(ServerContext *context, std::string action)
|
||||
{
|
||||
- const std::multimap<grpc::string_ref, grpc::string_ref> init_metadata = context->client_metadata();
|
||||
+ const std::multimap<grpc::string_ref, grpc::string_ref> &init_metadata = context->client_metadata();
|
||||
auto tls_mode_kv = init_metadata.find("tls_mode");
|
||||
if (tls_mode_kv == init_metadata.end()) {
|
||||
return Status(StatusCode::UNKNOWN, "unknown error");
|
||||
@@ -58,4 +58,3 @@ Status auth(ServerContext *context, std::string action)
|
||||
return Status::OK;
|
||||
}
|
||||
} // namespace GrpcServerTlsAuth
|
||||
-
|
||||
diff --git a/src/daemon/entry/connect/grpc/grpc_server_tls_auth.h b/src/daemon/entry/connect/grpc/grpc_server_tls_auth.h
|
||||
index f490ef86..ee66529f 100644
|
||||
--- a/src/daemon/entry/connect/grpc/grpc_server_tls_auth.h
|
||||
+++ b/src/daemon/entry/connect/grpc/grpc_server_tls_auth.h
|
||||
@@ -24,11 +24,10 @@ using grpc::StatusCode;
|
||||
|
||||
namespace AuthorizationPluginConfig {
|
||||
extern std::string auth_plugin;
|
||||
-};
|
||||
+}; // namespace AuthorizationPluginConfig
|
||||
|
||||
namespace GrpcServerTlsAuth {
|
||||
Status auth(ServerContext *context, std::string action);
|
||||
-};
|
||||
+}; // namespace GrpcServerTlsAuth
|
||||
|
||||
#endif // DAEMON_ENTRY_CONNECT_GRPC_GRPC_SERVER_TLS_AUTH_H
|
||||
-
|
||||
diff --git a/src/daemon/entry/connect/grpc/grpc_volumes_service.cc b/src/daemon/entry/connect/grpc/grpc_volumes_service.cc
|
||||
index fcc7210e..8b090486 100644
|
||||
--- a/src/daemon/entry/connect/grpc/grpc_volumes_service.cc
|
||||
+++ b/src/daemon/entry/connect/grpc/grpc_volumes_service.cc
|
||||
@@ -28,8 +28,7 @@
|
||||
int VolumeServiceImpl::volume_list_request_from_grpc(const ListVolumeRequest *grequest,
|
||||
volume_list_volume_request **request)
|
||||
{
|
||||
- volume_list_volume_request *tmpreq =
|
||||
- static_cast<volume_list_volume_request *>(util_common_calloc_s(sizeof(volume_list_volume_request)));
|
||||
+ auto *tmpreq = static_cast<volume_list_volume_request *>(util_common_calloc_s(sizeof(volume_list_volume_request)));
|
||||
if (tmpreq == nullptr) {
|
||||
ERROR("Out of memory");
|
||||
return -1;
|
||||
@@ -53,7 +52,7 @@ int VolumeServiceImpl::volume_list_response_to_grpc(volume_list_volume_response
|
||||
}
|
||||
|
||||
for (size_t i {}; i < response->volumes_len; i++) {
|
||||
- auto volume = gresponse->add_volumes();
|
||||
+ auto *volume = gresponse->add_volumes();
|
||||
if (response->volumes[i]->driver != nullptr) {
|
||||
volume->set_driver(response->volumes[i]->driver);
|
||||
}
|
||||
@@ -68,7 +67,7 @@ int VolumeServiceImpl::volume_list_response_to_grpc(volume_list_volume_response
|
||||
int VolumeServiceImpl::volume_remove_request_from_grpc(const RemoveVolumeRequest *grequest,
|
||||
volume_remove_volume_request **request)
|
||||
{
|
||||
- volume_remove_volume_request *tmpreq =
|
||||
+ auto *tmpreq =
|
||||
static_cast<volume_remove_volume_request *>(util_common_calloc_s(sizeof(volume_remove_volume_request)));
|
||||
if (tmpreq == nullptr) {
|
||||
ERROR("Out of memory");
|
||||
@@ -86,7 +85,7 @@ int VolumeServiceImpl::volume_remove_request_from_grpc(const RemoveVolumeRequest
|
||||
int VolumeServiceImpl::volume_prune_request_from_grpc(const PruneVolumeRequest *grequest,
|
||||
volume_prune_volume_request **request)
|
||||
{
|
||||
- volume_prune_volume_request *tmpreq =
|
||||
+ auto *tmpreq =
|
||||
static_cast<volume_prune_volume_request *>(util_common_calloc_s(sizeof(volume_prune_volume_request)));
|
||||
if (tmpreq == nullptr) {
|
||||
ERROR("Out of memory");
|
||||
@@ -117,14 +116,13 @@ int VolumeServiceImpl::volume_prune_response_to_grpc(volume_prune_volume_respons
|
||||
return 0;
|
||||
}
|
||||
|
||||
-
|
||||
Status VolumeServiceImpl::List(ServerContext *context, const ListVolumeRequest *request, ListVolumeResponse *reply)
|
||||
{
|
||||
auto status = GrpcServerTlsAuth::auth(context, "volume_list");
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
- auto cb = get_service_executor();
|
||||
+ auto *cb = get_service_executor();
|
||||
if (cb == nullptr || cb->volume.list == nullptr) {
|
||||
return Status(StatusCode::UNIMPLEMENTED, "Unimplemented callback");
|
||||
}
|
||||
diff --git a/src/daemon/entry/cri/cri_constants.cc b/src/daemon/entry/cri/cri_constants.cc
|
||||
index 265e38e5..86cc2bb6 100644
|
||||
--- a/src/daemon/entry/cri/cri_constants.cc
|
||||
+++ b/src/daemon/entry/cri/cri_constants.cc
|
||||
@@ -12,7 +12,7 @@
|
||||
* Create: 2020-12-21
|
||||
* Description: provide cri constants definition
|
||||
*********************************************************************************/
|
||||
-# include "cri_constants.h"
|
||||
+#include "cri_constants.h"
|
||||
|
||||
namespace CRI {
|
||||
const std::string Constants::namespaceModeHost { "host" };
|
||||
@@ -22,4 +22,4 @@ const std::string Constants::kubePrefix { "k8s" };
|
||||
const std::string Constants::sandboxContainerName { "POD" };
|
||||
const std::string Constants::kubeAPIVersion { "0.1.0" };
|
||||
const std::string Constants::iSulaRuntimeName { "iSulad" };
|
||||
-}
|
||||
\ No newline at end of file
|
||||
+} // namespace CRI
|
||||
diff --git a/src/daemon/entry/cri/errors.cc b/src/daemon/entry/cri/errors.cc
|
||||
index 0dbee4a7..a80ca433 100644
|
||||
--- a/src/daemon/entry/cri/errors.cc
|
||||
+++ b/src/daemon/entry/cri/errors.cc
|
||||
@@ -90,7 +90,7 @@ void Errors::SetAggregate(const std::vector<std::string> &msgs)
|
||||
std::string result;
|
||||
size_t size = msgs.size();
|
||||
|
||||
- if (!size) {
|
||||
+ if (size == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
diff --git a/src/daemon/entry/cri/errors.h b/src/daemon/entry/cri/errors.h
|
||||
index 81e82ad2..193a9523 100644
|
||||
--- a/src/daemon/entry/cri/errors.h
|
||||
+++ b/src/daemon/entry/cri/errors.h
|
||||
@@ -44,7 +44,7 @@ public:
|
||||
|
||||
private:
|
||||
std::string m_message;
|
||||
- int m_code;
|
||||
+ int m_code{0};
|
||||
};
|
||||
|
||||
#endif // DAEMON_ENTRY_CRI_ERRORS_H
|
||||
diff --git a/src/daemon/entry/cri/network_plugin.cc b/src/daemon/entry/cri/network_plugin.cc
|
||||
index 2fa6ac26..00be975e 100644
|
||||
--- a/src/daemon/entry/cri/network_plugin.cc
|
||||
+++ b/src/daemon/entry/cri/network_plugin.cc
|
||||
@@ -27,7 +27,7 @@
|
||||
#include "cri_runtime_service.h"
|
||||
|
||||
namespace Network {
|
||||
-static void run_modprobe(void *args)
|
||||
+static void run_modprobe(void * /*args*/)
|
||||
{
|
||||
execlp("modprobe", "modprobe", "br-netfilter", nullptr);
|
||||
}
|
||||
@@ -190,7 +190,7 @@ void InitNetworkPlugin(std::vector<std::shared_ptr<NetworkPlugin>> *plugins, std
|
||||
std::string hairpinMode, std::string nonMasqueradeCIDR, int mtu,
|
||||
std::shared_ptr<NetworkPlugin> *result, Errors &err)
|
||||
{
|
||||
- std::string allErr { "" };
|
||||
+ std::string allErr;
|
||||
|
||||
if (networkPluginName.empty()) {
|
||||
DEBUG("network plugin name empty");
|
||||
@@ -233,7 +233,6 @@ void InitNetworkPlugin(std::vector<std::shared_ptr<NetworkPlugin>> *plugins, std
|
||||
}
|
||||
|
||||
pluginMap.clear();
|
||||
- return;
|
||||
}
|
||||
|
||||
const std::string &NetworkPluginConf::GetDockershimRootDirectory() const
|
||||
@@ -485,8 +484,8 @@ unlock:
|
||||
Unlock(fullName, error);
|
||||
}
|
||||
|
||||
-void NoopNetworkPlugin::Init(const std::string &hairpinMode,
|
||||
- const std::string &nonMasqueradeCIDR, int mtu, Errors &error)
|
||||
+void NoopNetworkPlugin::Init(const std::string &hairpinMode, const std::string &nonMasqueradeCIDR, int mtu,
|
||||
+ Errors &error)
|
||||
{
|
||||
char *stderr_str { nullptr };
|
||||
char *stdout_str { nullptr };
|
||||
diff --git a/src/daemon/entry/cri/request_cache.cc b/src/daemon/entry/cri/request_cache.cc
|
||||
index 312a8071..36a2f3dc 100644
|
||||
--- a/src/daemon/entry/cri/request_cache.cc
|
||||
+++ b/src/daemon/entry/cri/request_cache.cc
|
||||
@@ -94,7 +94,7 @@ std::string RequestCache::UniqueToken()
|
||||
for (int i {}; i < maxTries; ++i) {
|
||||
char rawToken[rawTokenSize + 1];
|
||||
(void)memset(rawToken, 0, sizeof(rawToken));
|
||||
- if (util_generate_random_str(rawToken, (size_t)rawTokenSize)) {
|
||||
+ if (util_generate_random_str(rawToken, (size_t)rawTokenSize) != 0) {
|
||||
ERROR("Generate rawToken failed");
|
||||
continue;
|
||||
}
|
||||
diff --git a/src/daemon/entry/cri/websocket/service/exec_serve.cc b/src/daemon/entry/cri/websocket/service/exec_serve.cc
|
||||
index bf41cb74..7b7d36b5 100644
|
||||
--- a/src/daemon/entry/cri/websocket/service/exec_serve.cc
|
||||
+++ b/src/daemon/entry/cri/websocket/service/exec_serve.cc
|
||||
@@ -88,7 +88,7 @@ int ExecServe::ExecuteStreamCommand(SessionData *lwsCtx, void *request)
|
||||
int ret = cb->container.exec(m_request, &m_response, m_request->attach_stdin ? lwsCtx->pipes.at(0) : -1,
|
||||
m_request->attach_stdout ? &StdoutstringWriter : nullptr,
|
||||
m_request->attach_stderr ? &StderrstringWriter : nullptr);
|
||||
-
|
||||
+
|
||||
if (ret != 0) {
|
||||
std::string message;
|
||||
if (m_response != nullptr && m_response->errmsg != nullptr) {
|
||||
diff --git a/src/daemon/entry/cri/websocket/service/ws_server.h b/src/daemon/entry/cri/websocket/service/ws_server.h
|
||||
index 2d3bb4a7..4af54067 100644
|
||||
--- a/src/daemon/entry/cri/websocket/service/ws_server.h
|
||||
+++ b/src/daemon/entry/cri/websocket/service/ws_server.h
|
||||
@@ -23,6 +23,7 @@
|
||||
#include <memory>
|
||||
#include <list>
|
||||
#include <thread>
|
||||
+#include <array>
|
||||
#include <libwebsockets.h>
|
||||
#include "route_callback_register.h"
|
||||
#include "url.h"
|
||||
--
|
||||
2.20.1
|
||||
|
||||
@ -1,187 +0,0 @@
|
||||
From fb14a10d2e9bdf700dac71078327f9473ee06ed7 Mon Sep 17 00:00:00 2001
|
||||
From: wujing <wujing50@huawei.com>
|
||||
Date: Mon, 28 Feb 2022 20:51:06 +0800
|
||||
Subject: [PATCH 13/16] fix coding irregularities
|
||||
|
||||
Signed-off-by: wujing <wujing50@huawei.com>
|
||||
---
|
||||
src/cmd/isulad/isulad_commands.c | 2 +-
|
||||
src/daemon/common/selinux_label.c | 2 --
|
||||
src/daemon/common/sysinfo.c | 15 +++++++--------
|
||||
.../executor/container_cb/execution_create.c | 2 +-
|
||||
.../executor/container_cb/execution_network.c | 2 +-
|
||||
src/daemon/executor/container_cb/list.c | 11 +----------
|
||||
6 files changed, 11 insertions(+), 23 deletions(-)
|
||||
|
||||
diff --git a/src/cmd/isulad/isulad_commands.c b/src/cmd/isulad/isulad_commands.c
|
||||
index b37c7208..2a0ccf92 100644
|
||||
--- a/src/cmd/isulad/isulad_commands.c
|
||||
+++ b/src/cmd/isulad/isulad_commands.c
|
||||
@@ -360,7 +360,7 @@ static int check_args_auth_plugin(const struct service_arguments *args)
|
||||
int ret = 0;
|
||||
|
||||
if (args->json_confs->authorization_plugin != NULL) {
|
||||
- if (strcmp(args->json_confs->authorization_plugin, AUTH_PLUGIN)) {
|
||||
+ if (strcmp(args->json_confs->authorization_plugin, AUTH_PLUGIN) != 0) {
|
||||
COMMAND_ERROR("Invalid authorization plugin '%s'", args->json_confs->authorization_plugin);
|
||||
ERROR("Invalid authorization plugin '%s'", args->json_confs->authorization_plugin);
|
||||
ret = -1;
|
||||
diff --git a/src/daemon/common/selinux_label.c b/src/daemon/common/selinux_label.c
|
||||
index f6698e89..4472504d 100644
|
||||
--- a/src/daemon/common/selinux_label.c
|
||||
+++ b/src/daemon/common/selinux_label.c
|
||||
@@ -171,8 +171,6 @@ static void find_selinux_fs(char **fs)
|
||||
}
|
||||
// slow path: try to find among the mounts
|
||||
find_selinux_fs_among_mounts(fs);
|
||||
-
|
||||
- return;
|
||||
}
|
||||
|
||||
static int get_state_selinuxfs(char **fs)
|
||||
diff --git a/src/daemon/common/sysinfo.c b/src/daemon/common/sysinfo.c
|
||||
index 652a3985..e60377dd 100644
|
||||
--- a/src/daemon/common/sysinfo.c
|
||||
+++ b/src/daemon/common/sysinfo.c
|
||||
@@ -1010,7 +1010,7 @@ free_out:
|
||||
|
||||
static int get_cgroup_version()
|
||||
{
|
||||
- struct statfs fs = {0};
|
||||
+ struct statfs fs = { 0 };
|
||||
|
||||
if (statfs(CGROUP_MOUNTPOINT, &fs) != 0) {
|
||||
ERROR("failed to statfs %s: %s", CGROUP_MOUNTPOINT, strerror(errno));
|
||||
@@ -1019,9 +1019,9 @@ static int get_cgroup_version()
|
||||
|
||||
if (fs.f_type == CGROUP2_SUPER_MAGIC) {
|
||||
return CGROUP_VERSION_2;
|
||||
- } else {
|
||||
- return CGROUP_VERSION_1;
|
||||
}
|
||||
+
|
||||
+ return CGROUP_VERSION_1;
|
||||
}
|
||||
|
||||
static bool is_hugetlb_max(const char *name)
|
||||
@@ -1102,7 +1102,6 @@ static char **get_huge_page_sizes()
|
||||
hps[index] = util_strdup_s(pos);
|
||||
dup_free:
|
||||
free(dup);
|
||||
- continue;
|
||||
}
|
||||
free_out:
|
||||
|
||||
@@ -1259,7 +1258,7 @@ static int cgroup2_enable_all()
|
||||
char *controllers_str = NULL;
|
||||
char *subtree_controller_str = NULL;
|
||||
char **controllers = NULL;
|
||||
- char enable_controllers[PATH_MAX] = {0};
|
||||
+ char enable_controllers[PATH_MAX] = { 0 };
|
||||
|
||||
controllers_str = util_read_content_from_file(CGROUP2_CONTROLLERS_PATH);
|
||||
if (controllers_str == NULL || strlen(controllers_str) == 0 ||
|
||||
@@ -1329,7 +1328,7 @@ static int get_cgroup_info_v2(sysinfo_t *sysinfo, bool quiet)
|
||||
int ret = 0;
|
||||
int nret = 0;
|
||||
char *size = NULL;
|
||||
- char path[PATH_MAX] = {0};
|
||||
+ char path[PATH_MAX] = { 0 };
|
||||
|
||||
if (make_sure_cgroup2_isulad_path_exist() != 0) {
|
||||
return -1;
|
||||
@@ -1511,7 +1510,7 @@ mountinfo_t *get_mount_info(const char *pline)
|
||||
|
||||
info->mountpoint = util_strdup_s(list[4]);
|
||||
|
||||
- if (strcmp(list[6], "-")) {
|
||||
+ if (strcmp(list[6], "-") != 0) {
|
||||
info->optional = util_strdup_s(list[6]);
|
||||
}
|
||||
|
||||
@@ -1570,7 +1569,7 @@ mountinfo_t **getmountsinfo(void)
|
||||
|
||||
while (getline(&pline, &length, fp) != -1) {
|
||||
int index;
|
||||
- mountinfo_t *info;
|
||||
+ mountinfo_t *info = NULL;
|
||||
|
||||
info = get_mount_info(pline);
|
||||
if (info == NULL) {
|
||||
diff --git a/src/daemon/executor/container_cb/execution_create.c b/src/daemon/executor/container_cb/execution_create.c
|
||||
index 43734d19..850e0a0f 100644
|
||||
--- a/src/daemon/executor/container_cb/execution_create.c
|
||||
+++ b/src/daemon/executor/container_cb/execution_create.c
|
||||
@@ -1026,7 +1026,7 @@ static int get_request_image_info(const container_create_request *request, char
|
||||
}
|
||||
|
||||
// Do not use none image because none image has no config.
|
||||
- if (strcmp(request->image, "none") && strcmp(request->image, "none:latest")) {
|
||||
+ if (strcmp(request->image, "none") != 0 && strcmp(request->image, "none:latest") != 0) {
|
||||
*image_name = util_strdup_s(request->image);
|
||||
}
|
||||
|
||||
diff --git a/src/daemon/executor/container_cb/execution_network.c b/src/daemon/executor/container_cb/execution_network.c
|
||||
index d10e9d16..6ca79a8c 100644
|
||||
--- a/src/daemon/executor/container_cb/execution_network.c
|
||||
+++ b/src/daemon/executor/container_cb/execution_network.c
|
||||
@@ -1074,4 +1074,4 @@ int init_container_network_confs(const char *id, const char *rootpath, const hos
|
||||
|
||||
out:
|
||||
return ret;
|
||||
-}
|
||||
\ No newline at end of file
|
||||
+}
|
||||
diff --git a/src/daemon/executor/container_cb/list.c b/src/daemon/executor/container_cb/list.c
|
||||
index 67fef06e..90f4a548 100644
|
||||
--- a/src/daemon/executor/container_cb/list.c
|
||||
+++ b/src/daemon/executor/container_cb/list.c
|
||||
@@ -173,8 +173,7 @@ static int insert_matched_id(char **ids, map_t *matches, void *value, size_t ids
|
||||
for (i = 0; i < ids_len; i++) {
|
||||
container_t *cont = containers_store_get_by_prefix(ids[i]);
|
||||
if (cont != NULL) {
|
||||
- bool inserted;
|
||||
- inserted = map_insert(matches, cont->common_config->id, value);
|
||||
+ bool inserted = map_insert(matches, cont->common_config->id, value);
|
||||
container_unref(cont);
|
||||
if (!inserted) {
|
||||
ERROR("Insert map failed: %s", ids[i]);
|
||||
@@ -328,8 +327,6 @@ static void dup_container_labels(const map_t *map_labels, const container_config
|
||||
ERROR("Failed to dup container %s labels", common_config->id);
|
||||
}
|
||||
}
|
||||
-
|
||||
- return;
|
||||
}
|
||||
|
||||
static void dup_container_annotations(const container_config_v2_common_config *common_config,
|
||||
@@ -345,8 +342,6 @@ static void dup_container_annotations(const container_config_v2_common_config *c
|
||||
if (ret != 0) {
|
||||
ERROR("Failed to dup container %s annotations", common_config->id);
|
||||
}
|
||||
-
|
||||
- return;
|
||||
}
|
||||
|
||||
static void dup_container_created_time(const container_config_v2_common_config *common_config,
|
||||
@@ -356,8 +351,6 @@ static void dup_container_created_time(const container_config_v2_common_config *
|
||||
util_to_unix_nanos_from_str(common_config->created, &isuladinfo->created) != 0) {
|
||||
ERROR("Failed to dup container %s created time", common_config->id);
|
||||
}
|
||||
-
|
||||
- return;
|
||||
}
|
||||
|
||||
static void dup_container_image_ref(const container_config_v2_common_config *common_config,
|
||||
@@ -368,8 +361,6 @@ static void dup_container_image_ref(const container_config_v2_common_config *com
|
||||
}
|
||||
|
||||
isuladinfo->image_ref = util_strdup_s(common_config->config->image_ref);
|
||||
-
|
||||
- return;
|
||||
}
|
||||
|
||||
static int convert_common_config_info(const map_t *map_labels, const container_config_v2_common_config *common_config,
|
||||
--
|
||||
2.20.1
|
||||
|
||||
@ -1,275 +0,0 @@
|
||||
From 2ee5027ad7d9cd073ea2428a39c693f9c8963bfc Mon Sep 17 00:00:00 2001
|
||||
From: haozi007 <liuhao27@huawei.com>
|
||||
Date: Fri, 13 May 2022 10:31:02 +0100
|
||||
Subject: [PATCH 14/16] fix ut bug and arguments check
|
||||
|
||||
1. hold_int must return error when invalid digits, ie. "root:x:1a";
|
||||
2. hold_string_list return NULL only overflow buffer, other return buff_start;
|
||||
3. parse_line_gr must check hold_string_list return;
|
||||
4. must check result argument is not NULL;
|
||||
5. use '\xff' to check buffer is overflow;
|
||||
|
||||
Signed-off-by: haozi007 <liuhao27@huawei.com>
|
||||
---
|
||||
.../modules/image/image_rootfs_handler.c | 2 +-
|
||||
src/utils/cutils/utils_pwgr.c | 47 ++++++++++++++-----
|
||||
test/cutils/utils_pwgr/group_sample | 1 +
|
||||
test/cutils/utils_pwgr/passwd_sample | 1 +
|
||||
test/cutils/utils_pwgr/utils_pwgr_ut.cc | 20 +++++---
|
||||
5 files changed, 51 insertions(+), 20 deletions(-)
|
||||
|
||||
diff --git a/src/daemon/modules/image/image_rootfs_handler.c b/src/daemon/modules/image/image_rootfs_handler.c
|
||||
index 960d52c7..ac1afdc6 100644
|
||||
--- a/src/daemon/modules/image/image_rootfs_handler.c
|
||||
+++ b/src/daemon/modules/image/image_rootfs_handler.c
|
||||
@@ -84,7 +84,7 @@ static int proc_by_fpasswd(FILE *f_passwd, const char *user, defs_process_user *
|
||||
int uret = -1;
|
||||
bool userfound = false;
|
||||
long long n_user = 0;
|
||||
- char buf[BUFSIZ];
|
||||
+ char buf[BUFSIZ] = { 0 };
|
||||
struct passwd pw;
|
||||
struct passwd *pwbufp = NULL;
|
||||
|
||||
diff --git a/src/utils/cutils/utils_pwgr.c b/src/utils/cutils/utils_pwgr.c
|
||||
index f4588268..17cf017b 100644
|
||||
--- a/src/utils/cutils/utils_pwgr.c
|
||||
+++ b/src/utils/cutils/utils_pwgr.c
|
||||
@@ -57,6 +57,10 @@ static int hold_int(const char delim, bool required, char **src, unsigned int *d
|
||||
}
|
||||
|
||||
res = strtoll(*src, &err_str, 0);
|
||||
+ if (err_str == *src) {
|
||||
+ ERROR("invalid digits string.");
|
||||
+ return -1;
|
||||
+ }
|
||||
if (errno == ERANGE) {
|
||||
ERROR("Parse int from string failed.");
|
||||
return -1;
|
||||
@@ -158,9 +162,6 @@ static char **hold_string_list(char **line, char *buf_start, char *buf_end, cons
|
||||
char **result = NULL;
|
||||
char **walker = NULL;
|
||||
|
||||
- if (**line == '\0') {
|
||||
- return 0;
|
||||
- }
|
||||
// For ultimate space usage, the blank area from buffer which was allocated from stack is used
|
||||
buf_start += __alignof__(char *) - 1;
|
||||
// align the starting position of the buffer to use it as a 2d array
|
||||
@@ -174,7 +175,7 @@ static char **hold_string_list(char **line, char *buf_start, char *buf_end, cons
|
||||
(void)util_trim_space(*line);
|
||||
if (hold_string(',', line, walker) != 0) {
|
||||
ERROR("Parse string list error.");
|
||||
- return NULL;
|
||||
+ return result;
|
||||
}
|
||||
|
||||
if ((char *)(walker + 2) > buf_end) {
|
||||
@@ -218,6 +219,10 @@ static int parse_line_gr(const char delim, char *line, size_t buflen, struct gro
|
||||
}
|
||||
|
||||
result->gr_mem = hold_string_list(&line, freebuff, buffend, ',');
|
||||
+ if (result->gr_mem == NULL) {
|
||||
+ ERROR("overflow of buffer.");
|
||||
+ return -1;
|
||||
+ }
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -225,8 +230,10 @@ static int parse_line_gr(const char delim, char *line, size_t buflen, struct gro
|
||||
int util_getpwent_r(FILE *stream, struct passwd *resbuf, char *buffer, size_t buflen, struct passwd **result)
|
||||
{
|
||||
const char delim = ':';
|
||||
+ char *buff_end = NULL;
|
||||
+ bool got = false;
|
||||
|
||||
- if (stream == NULL || resbuf == NULL || buffer == NULL) {
|
||||
+ if (stream == NULL || resbuf == NULL || buffer == NULL || result == NULL) {
|
||||
ERROR("Password obj, params is NULL.");
|
||||
return -1;
|
||||
}
|
||||
@@ -242,28 +249,34 @@ int util_getpwent_r(FILE *stream, struct passwd *resbuf, char *buffer, size_t bu
|
||||
}
|
||||
|
||||
__fsetlocking(stream, FSETLOCKING_BYCALLER);
|
||||
- buffer[buflen - 1] = '\0';
|
||||
|
||||
if (feof(stream)) {
|
||||
*result = NULL;
|
||||
return ENOENT;
|
||||
}
|
||||
+ buff_end = buffer + buflen - 1;
|
||||
|
||||
- while (fgets(buffer, buflen, stream) != NULL) {
|
||||
+ while ((*buff_end = '\xff') && fgets(buffer, buflen, stream) != NULL) {
|
||||
(void)util_trim_space(buffer);
|
||||
if (buffer[0] == '\0' || buffer[0] == '#' || strlen(buffer) < 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (parse_line_pw(delim, buffer, resbuf) == 0) {
|
||||
+ got = true;
|
||||
break;
|
||||
}
|
||||
|
||||
- if (buffer[buflen - 1] != '\0') {
|
||||
+ if (*buff_end != '\xff') {
|
||||
*result = NULL;
|
||||
return ERANGE;
|
||||
}
|
||||
}
|
||||
+ if (!got) {
|
||||
+ *result = NULL;
|
||||
+ return ERANGE;
|
||||
+ }
|
||||
+
|
||||
*result = resbuf;
|
||||
|
||||
return 0;
|
||||
@@ -272,8 +285,10 @@ int util_getpwent_r(FILE *stream, struct passwd *resbuf, char *buffer, size_t bu
|
||||
int util_getgrent_r(FILE *stream, struct group *resbuf, char *buffer, size_t buflen, struct group **result)
|
||||
{
|
||||
const char delim = ':';
|
||||
+ char *buff_end = NULL;
|
||||
+ bool got = false;
|
||||
|
||||
- if (stream == NULL || resbuf == NULL || buffer == NULL) {
|
||||
+ if (stream == NULL || resbuf == NULL || buffer == NULL || result == NULL) {
|
||||
ERROR("Group obj, params is NULL.");
|
||||
return -1;
|
||||
}
|
||||
@@ -289,29 +304,35 @@ int util_getgrent_r(FILE *stream, struct group *resbuf, char *buffer, size_t buf
|
||||
}
|
||||
|
||||
__fsetlocking(stream, FSETLOCKING_BYCALLER);
|
||||
- buffer[buflen - 1] = '\0';
|
||||
|
||||
if (feof(stream)) {
|
||||
*result = NULL;
|
||||
return ENOENT;
|
||||
}
|
||||
+ buff_end = buffer + buflen - 1;
|
||||
|
||||
- while (fgets(buffer, buflen, stream) != NULL) {
|
||||
+ while ((*buff_end = '\xff') && fgets(buffer, buflen, stream) != NULL) {
|
||||
(void)util_trim_space(buffer);
|
||||
if (buffer[0] == '\0' || buffer[0] == '#' || strlen(buffer) < 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (parse_line_gr(delim, buffer, buflen, resbuf) == 0) {
|
||||
+ got = true;
|
||||
break;
|
||||
}
|
||||
|
||||
- if (buffer[buflen - 1] != '\0') {
|
||||
+ if (*buff_end != '\xff') {
|
||||
*result = NULL;
|
||||
return ERANGE;
|
||||
}
|
||||
}
|
||||
- *result = resbuf;
|
||||
|
||||
+ if (!got) {
|
||||
+ *result = NULL;
|
||||
+ return ERANGE;
|
||||
+ }
|
||||
+
|
||||
+ *result = resbuf;
|
||||
return 0;
|
||||
}
|
||||
\ No newline at end of file
|
||||
diff --git a/test/cutils/utils_pwgr/group_sample b/test/cutils/utils_pwgr/group_sample
|
||||
index c73883cc..8de62df2 100644
|
||||
--- a/test/cutils/utils_pwgr/group_sample
|
||||
+++ b/test/cutils/utils_pwgr/group_sample
|
||||
@@ -1,3 +1,4 @@
|
||||
+root:x:a
|
||||
root:x:0:
|
||||
#bin:x:1:
|
||||
|
||||
diff --git a/test/cutils/utils_pwgr/passwd_sample b/test/cutils/utils_pwgr/passwd_sample
|
||||
index 76853454..995dea3a 100644
|
||||
--- a/test/cutils/utils_pwgr/passwd_sample
|
||||
+++ b/test/cutils/utils_pwgr/passwd_sample
|
||||
@@ -1,3 +1,4 @@
|
||||
+root:x:b:0:
|
||||
root:x:0:0:root:/root:/bin/bash
|
||||
bin:x:1:1:bin:/bin:/sbin/nologin
|
||||
bin:x:-1:1:bin:/bin:/sbin/nologin
|
||||
diff --git a/test/cutils/utils_pwgr/utils_pwgr_ut.cc b/test/cutils/utils_pwgr/utils_pwgr_ut.cc
|
||||
index 1ed8eaa1..d856270d 100644
|
||||
--- a/test/cutils/utils_pwgr/utils_pwgr_ut.cc
|
||||
+++ b/test/cutils/utils_pwgr/utils_pwgr_ut.cc
|
||||
@@ -25,7 +25,10 @@ TEST(utils_pwgr, test_getpwent_r)
|
||||
struct passwd pw;
|
||||
struct passwd *ppw = nullptr;
|
||||
struct passwd *ppw_alter = &pw;
|
||||
- char buf[BUFSIZ];
|
||||
+ char buf[BUFSIZ] = { 0 };
|
||||
+ char invalid_buf[1] = { 0 };
|
||||
+ // use to get ERANGE error
|
||||
+ char small_buf[10] = { 0 };
|
||||
|
||||
std::vector<std::tuple<std::string, std::string, int, int, std::string, std::string, std::string>> testcase = {
|
||||
std::make_tuple("root", "x", 0, 0, "root", "/root", "/bin/bash"),
|
||||
@@ -39,7 +42,7 @@ TEST(utils_pwgr, test_getpwent_r)
|
||||
|
||||
ASSERT_EQ(util_getpwent_r(NULL, &pw, buf, sizeof(buf), &ppw), -1);
|
||||
ASSERT_EQ(util_getpwent_r(f_pw, &pw, NULL, 0, &ppw), -1);
|
||||
- ASSERT_EQ(util_getpwent_r(f_pw, &pw, NULL, 1, &ppw), -1);
|
||||
+ ASSERT_EQ(util_getpwent_r(f_pw, &pw, invalid_buf, 1, &ppw), -1);
|
||||
ASSERT_EQ(util_getpwent_r(f_pw, &pw, buf, sizeof(buf), &ppw_alter), -1);
|
||||
|
||||
while (!feof(f_pw)) {
|
||||
@@ -48,6 +51,8 @@ TEST(utils_pwgr, test_getpwent_r)
|
||||
ASSERT_EQ(util_getpwent_r(f_pw, &pw, buf, sizeof(buf), &ppw), ENOENT);
|
||||
rewind(f_pw);
|
||||
|
||||
+ ASSERT_EQ(util_getpwent_r(f_pw, &pw, small_buf, sizeof(small_buf), &ppw), ERANGE);
|
||||
+
|
||||
for (const auto &elem : testcase) {
|
||||
ASSERT_EQ(util_getpwent_r(f_pw, &pw, buf, sizeof(buf), &ppw), 0);
|
||||
ASSERT_STREQ(pw.pw_name, std::get<0>(elem).c_str());
|
||||
@@ -74,7 +79,10 @@ TEST(utils_pwgr, test_getgrent_r)
|
||||
struct group gr{0};
|
||||
struct group *pgr = nullptr;
|
||||
struct group *pgr_alter = &gr;
|
||||
- char buf[BUFSIZ];
|
||||
+ char buf[BUFSIZ] = { 0 };
|
||||
+ char invalid_buf[1] = { 0 };
|
||||
+ // use to get ERANGE error
|
||||
+ char small_buf[9] = { 0 };
|
||||
size_t i = 0;
|
||||
size_t j = 0;
|
||||
std::vector<std::vector<std::string>> string_list{
|
||||
@@ -95,7 +103,7 @@ TEST(utils_pwgr, test_getgrent_r)
|
||||
|
||||
ASSERT_EQ(util_getgrent_r(NULL, &gr, buf, sizeof(buf), &pgr), -1);
|
||||
ASSERT_EQ(util_getgrent_r(f_gr, &gr, NULL, 0, &pgr), -1);
|
||||
- ASSERT_EQ(util_getgrent_r(f_gr, &gr, NULL, 1, &pgr), -1);
|
||||
+ ASSERT_EQ(util_getgrent_r(f_gr, &gr, invalid_buf, 1, &pgr), -1);
|
||||
ASSERT_EQ(util_getgrent_r(f_gr, &gr, buf, sizeof(buf), &pgr_alter), -1);
|
||||
|
||||
while (!feof(f_gr)) {
|
||||
@@ -104,6 +112,8 @@ TEST(utils_pwgr, test_getgrent_r)
|
||||
ASSERT_EQ(util_getgrent_r(f_gr, &gr, buf, sizeof(buf), &pgr), ENOENT);
|
||||
rewind(f_gr);
|
||||
|
||||
+ ASSERT_EQ(util_getgrent_r(f_gr, &gr, small_buf, sizeof(small_buf), &pgr), ERANGE);
|
||||
+
|
||||
for (; i < string_list.size(); ++i) {
|
||||
ASSERT_EQ(util_getgrent_r(f_gr, &gr, buf, sizeof(buf), &pgr), 0);
|
||||
ASSERT_STREQ(gr.gr_name, std::get<0>(testcase[i]).c_str());
|
||||
@@ -113,8 +123,6 @@ TEST(utils_pwgr, test_getgrent_r)
|
||||
for (j = 0; j < string_list[i].size(); ++j) {
|
||||
EXPECT_TRUE(strcmp(gr.gr_mem[j], string_list[i][j].c_str()) == 0);
|
||||
}
|
||||
- } else {
|
||||
- EXPECT_TRUE(gr.gr_mem == nullptr);
|
||||
}
|
||||
EXPECT_TRUE(pgr == &gr);
|
||||
gr = {0};
|
||||
--
|
||||
2.20.1
|
||||
|
||||
@ -1,408 +0,0 @@
|
||||
From 8da6dd20b73068e9d29fc8ed1469ade7b1dc2c12 Mon Sep 17 00:00:00 2001
|
||||
From: haozi007 <liuhao27@huawei.com>
|
||||
Date: Sat, 14 May 2022 09:55:18 +0100
|
||||
Subject: [PATCH 15/16] refactor util_getgrent_r and util_getpwent_r
|
||||
|
||||
Signed-off-by: haozi007 <liuhao27@huawei.com>
|
||||
---
|
||||
src/utils/cutils/utils_pwgr.c | 215 +++++++++++-------------
|
||||
test/cutils/utils_pwgr/passwd_sample | 8 +-
|
||||
test/cutils/utils_pwgr/utils_pwgr_ut.cc | 8 +-
|
||||
3 files changed, 109 insertions(+), 122 deletions(-)
|
||||
|
||||
diff --git a/src/utils/cutils/utils_pwgr.c b/src/utils/cutils/utils_pwgr.c
|
||||
index 17cf017b..f8e4a18e 100644
|
||||
--- a/src/utils/cutils/utils_pwgr.c
|
||||
+++ b/src/utils/cutils/utils_pwgr.c
|
||||
@@ -29,100 +29,82 @@
|
||||
|
||||
static int hold_int(const char delim, bool required, char **src, unsigned int *dst)
|
||||
{
|
||||
- long long res = 0;
|
||||
- char *walker = *src;
|
||||
+ unsigned long long int res = 0;
|
||||
char *err_str = NULL;
|
||||
|
||||
+ // ensure *src not a empty string
|
||||
if (**src == '\0') {
|
||||
ERROR("Empty subject on given entrie is not allowed.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
- while (*walker != delim) {
|
||||
- if (*walker == '\0') {
|
||||
- break;
|
||||
- }
|
||||
- ++walker;
|
||||
- }
|
||||
-
|
||||
- if (*walker == **src) {
|
||||
- if (required) { // deafult 0 while required full content but integer part is missing
|
||||
- *dst = 0;
|
||||
- *src = walker + 1;
|
||||
- return 0;
|
||||
- }
|
||||
- ERROR("Integer part is missing.");
|
||||
- ++(*src);
|
||||
- return -1;
|
||||
- }
|
||||
-
|
||||
- res = strtoll(*src, &err_str, 0);
|
||||
- if (err_str == *src) {
|
||||
- ERROR("invalid digits string.");
|
||||
- return -1;
|
||||
- }
|
||||
+ // covert string to long long
|
||||
+ res = strtoull(*src, &err_str, 0);
|
||||
+ // large digit string, return error
|
||||
if (errno == ERANGE) {
|
||||
ERROR("Parse int from string failed.");
|
||||
return -1;
|
||||
}
|
||||
- if (res < 0) {
|
||||
- ERROR("Gid uid shall not be negative.");
|
||||
- return -1;
|
||||
+
|
||||
+ // **src is not a digit
|
||||
+ if (err_str == *src) {
|
||||
+ if (!required) {
|
||||
+ ERROR("Integer part is missing.");
|
||||
+ return -1;
|
||||
+ }
|
||||
+ // if required, just set 0
|
||||
+ *dst = 0;
|
||||
+ } else {
|
||||
+ if (sizeof(void *) > 4 && res > UINT_MAX) { // make sure 64-bit platform behave same as 32-bit
|
||||
+ res = UINT_MAX;
|
||||
+ }
|
||||
+ res = res & UINT_MAX;
|
||||
+ *dst = (uint32_t)res;
|
||||
}
|
||||
|
||||
- if (sizeof(void *) > 4 && res > UINT_MAX) { // make sure 64-bit platform behave same as 32-bit
|
||||
- res = UINT_MAX;
|
||||
+ // normal case
|
||||
+ if (*err_str == delim) {
|
||||
+ err_str++;
|
||||
+ } else if (*err_str != '\0') {
|
||||
+ ERROR("Invalid digit string.");
|
||||
+ return -1;
|
||||
}
|
||||
- res = res & UINT_MAX;
|
||||
- *dst = (uint32_t)res;
|
||||
- *src = err_str + 1; // update src to next valid context in line.
|
||||
|
||||
+ *src = err_str; // update src to next valid context in line.
|
||||
return 0;
|
||||
}
|
||||
|
||||
-static int hold_string(const char delim, char **src, char **dst)
|
||||
+static void hold_string(const char delim, char **src, char **dst)
|
||||
{
|
||||
- if (**src == delim) { // if src point to deliminator, content parsing is skiped.
|
||||
- *dst = "";
|
||||
- *src = *src + 1;
|
||||
- return 0;
|
||||
- }
|
||||
-
|
||||
- if (**src == '\0') {
|
||||
- return 0;
|
||||
- }
|
||||
-
|
||||
for (*dst = *src; **src != delim; ++(*src)) {
|
||||
if (**src == '\0') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
+
|
||||
if (**src == delim) {
|
||||
**src = '\0';
|
||||
++(*src);
|
||||
}
|
||||
-
|
||||
- return 0;
|
||||
}
|
||||
|
||||
static int parse_line_pw(const char delim, char *line, struct passwd *result)
|
||||
{
|
||||
int ret = 0;
|
||||
bool required = false;
|
||||
+ char *walker = NULL;
|
||||
|
||||
- ret = hold_string(delim, &line, &result->pw_name);
|
||||
- if (ret != 0) {
|
||||
- ERROR("Parse name error.");
|
||||
- return ret;
|
||||
+ walker = strpbrk(line, "\n");
|
||||
+ if (walker != NULL) {
|
||||
+ // clear newline char
|
||||
+ *walker = '\0';
|
||||
}
|
||||
|
||||
+ hold_string(delim, &line, &result->pw_name);
|
||||
+
|
||||
required = (result->pw_name[0] == '+' || result->pw_name[0] == '-') ? true : false;
|
||||
|
||||
- ret = hold_string(delim, &line, &result->pw_passwd);
|
||||
- if (ret != 0) {
|
||||
- ERROR("Parse passwd error.");
|
||||
- return ret;
|
||||
- }
|
||||
+ hold_string(delim, &line, &result->pw_passwd);
|
||||
|
||||
ret = hold_int(delim, required, &line, &result->pw_uid);
|
||||
if (ret != 0) {
|
||||
@@ -130,31 +112,20 @@ static int parse_line_pw(const char delim, char *line, struct passwd *result)
|
||||
ERROR("Parse uid error.");
|
||||
return ret;
|
||||
}
|
||||
+
|
||||
ret = hold_int(delim, required, &line, &result->pw_gid);
|
||||
if (ret != 0) {
|
||||
// it's ok to not provide gid
|
||||
ERROR("Parse gid error.");
|
||||
- }
|
||||
-
|
||||
- ret = hold_string(delim, &line, &result->pw_gecos);
|
||||
- if (ret != 0) {
|
||||
- ERROR("Parse gecos error.");
|
||||
return ret;
|
||||
}
|
||||
|
||||
- ret = hold_string(delim, &line, &result->pw_dir);
|
||||
- if (ret != 0) {
|
||||
- ERROR("Parse dir error.");
|
||||
- return ret;
|
||||
- }
|
||||
+ hold_string(delim, &line, &result->pw_gecos);
|
||||
|
||||
- ret = hold_string(delim, &line, &result->pw_shell);
|
||||
- if (ret != 0) {
|
||||
- ERROR("Parse shell error.");
|
||||
- return ret;
|
||||
- }
|
||||
+ hold_string(delim, &line, &result->pw_dir);
|
||||
|
||||
- return ret;
|
||||
+ result->pw_shell = line;
|
||||
+ return 0;
|
||||
}
|
||||
|
||||
static char **hold_string_list(char **line, char *buf_start, char *buf_end, const char terminator)
|
||||
@@ -172,42 +143,38 @@ static char **hold_string_list(char **line, char *buf_start, char *buf_end, cons
|
||||
walker = result;
|
||||
|
||||
for (; walker < (char **)buf_end; ++walker) {
|
||||
- (void)util_trim_space(*line);
|
||||
- if (hold_string(',', line, walker) != 0) {
|
||||
- ERROR("Parse string list error.");
|
||||
+ if (**line == '\0') {
|
||||
return result;
|
||||
}
|
||||
|
||||
+ (void)util_trim_space(*line);
|
||||
+ hold_string(',', line, walker);
|
||||
+
|
||||
if ((char *)(walker + 2) > buf_end) {
|
||||
return NULL;
|
||||
}
|
||||
-
|
||||
- if (**line == '\0') {
|
||||
- return result;
|
||||
- }
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
-static int parse_line_gr(const char delim, char *line, size_t buflen, struct group *result)
|
||||
+static int parse_line_gr(const char delim, char *line, char *buffend, struct group *result)
|
||||
{
|
||||
int ret = 0;
|
||||
bool rf = false;
|
||||
char *freebuff = line + 1 + strlen(line);
|
||||
- char *buffend = line + buflen;
|
||||
+ char *walker = NULL;
|
||||
|
||||
- ret = hold_string(delim, &line, &result->gr_name);
|
||||
- if (ret != 0) {
|
||||
- ERROR("Parse name error.");
|
||||
- return ret;
|
||||
+ walker = strpbrk(line, "\n");
|
||||
+ if (walker != NULL) {
|
||||
+ // clear newline char
|
||||
+ *walker = '\0';
|
||||
}
|
||||
|
||||
- ret = hold_string(delim, &line, &result->gr_passwd);
|
||||
- if (ret != 0) {
|
||||
- ERROR("Parse gecos error.");
|
||||
- return ret;
|
||||
- }
|
||||
+ hold_string(delim, &line, &result->gr_name);
|
||||
+
|
||||
+ hold_string(delim, &line, &result->gr_passwd);
|
||||
+
|
||||
if (result->gr_name[0] == '+' || result->gr_name[0] == '-') {
|
||||
rf = true;
|
||||
}
|
||||
@@ -231,6 +198,7 @@ int util_getpwent_r(FILE *stream, struct passwd *resbuf, char *buffer, size_t bu
|
||||
{
|
||||
const char delim = ':';
|
||||
char *buff_end = NULL;
|
||||
+ char *walker = NULL;
|
||||
bool got = false;
|
||||
|
||||
if (stream == NULL || resbuf == NULL || buffer == NULL || result == NULL) {
|
||||
@@ -250,27 +218,36 @@ int util_getpwent_r(FILE *stream, struct passwd *resbuf, char *buffer, size_t bu
|
||||
|
||||
__fsetlocking(stream, FSETLOCKING_BYCALLER);
|
||||
|
||||
- if (feof(stream)) {
|
||||
- *result = NULL;
|
||||
- return ENOENT;
|
||||
- }
|
||||
buff_end = buffer + buflen - 1;
|
||||
+ while (1) {
|
||||
+ *buff_end = '\xff';
|
||||
+ walker = fgets(buffer, buflen, stream);
|
||||
+ // if get NULL string
|
||||
+ if (walker == NULL) {
|
||||
+ *result = NULL;
|
||||
+ // reach end of file, return error
|
||||
+ if (feof(stream)) {
|
||||
+ return ENOENT;
|
||||
+ }
|
||||
+ // overflow buffer
|
||||
+ return ERANGE;
|
||||
+ }
|
||||
+ // just overflow last char in buffer
|
||||
+ if (*buff_end != '\xff') {
|
||||
+ *result = NULL;
|
||||
+ return ERANGE;
|
||||
+ }
|
||||
|
||||
- while ((*buff_end = '\xff') && fgets(buffer, buflen, stream) != NULL) {
|
||||
(void)util_trim_space(buffer);
|
||||
- if (buffer[0] == '\0' || buffer[0] == '#' || strlen(buffer) < 1) {
|
||||
+ // skip comment line and empty line
|
||||
+ if (walker[0] == '#' || walker[0] == '\0') {
|
||||
continue;
|
||||
}
|
||||
|
||||
- if (parse_line_pw(delim, buffer, resbuf) == 0) {
|
||||
+ if (parse_line_pw(delim, walker, resbuf) == 0) {
|
||||
got = true;
|
||||
break;
|
||||
}
|
||||
-
|
||||
- if (*buff_end != '\xff') {
|
||||
- *result = NULL;
|
||||
- return ERANGE;
|
||||
- }
|
||||
}
|
||||
if (!got) {
|
||||
*result = NULL;
|
||||
@@ -286,6 +263,7 @@ int util_getgrent_r(FILE *stream, struct group *resbuf, char *buffer, size_t buf
|
||||
{
|
||||
const char delim = ':';
|
||||
char *buff_end = NULL;
|
||||
+ char *walker = NULL;
|
||||
bool got = false;
|
||||
|
||||
if (stream == NULL || resbuf == NULL || buffer == NULL || result == NULL) {
|
||||
@@ -305,27 +283,36 @@ int util_getgrent_r(FILE *stream, struct group *resbuf, char *buffer, size_t buf
|
||||
|
||||
__fsetlocking(stream, FSETLOCKING_BYCALLER);
|
||||
|
||||
- if (feof(stream)) {
|
||||
- *result = NULL;
|
||||
- return ENOENT;
|
||||
- }
|
||||
buff_end = buffer + buflen - 1;
|
||||
+ while (1) {
|
||||
+ *buff_end = '\xff';
|
||||
+ walker = fgets(buffer, buflen, stream);
|
||||
+ // if get NULL string
|
||||
+ if (walker == NULL) {
|
||||
+ *result = NULL;
|
||||
+ // reach end of file, return error
|
||||
+ if (feof(stream)) {
|
||||
+ return ENOENT;
|
||||
+ }
|
||||
+ // overflow buffer
|
||||
+ return ERANGE;
|
||||
+ }
|
||||
+ // just overflow last char in buffer
|
||||
+ if (*buff_end != '\xff') {
|
||||
+ *result = NULL;
|
||||
+ return ERANGE;
|
||||
+ }
|
||||
|
||||
- while ((*buff_end = '\xff') && fgets(buffer, buflen, stream) != NULL) {
|
||||
- (void)util_trim_space(buffer);
|
||||
- if (buffer[0] == '\0' || buffer[0] == '#' || strlen(buffer) < 1) {
|
||||
+ (void)util_trim_space(walker);
|
||||
+ // skip comment line and empty line
|
||||
+ if (walker[0] == '#' || walker[0] == '\0') {
|
||||
continue;
|
||||
}
|
||||
|
||||
- if (parse_line_gr(delim, buffer, buflen, resbuf) == 0) {
|
||||
+ if (parse_line_gr(delim, walker, buff_end, resbuf) == 0) {
|
||||
got = true;
|
||||
break;
|
||||
}
|
||||
-
|
||||
- if (*buff_end != '\xff') {
|
||||
- *result = NULL;
|
||||
- return ERANGE;
|
||||
- }
|
||||
}
|
||||
|
||||
if (!got) {
|
||||
diff --git a/test/cutils/utils_pwgr/passwd_sample b/test/cutils/utils_pwgr/passwd_sample
|
||||
index 995dea3a..cdb1890d 100644
|
||||
--- a/test/cutils/utils_pwgr/passwd_sample
|
||||
+++ b/test/cutils/utils_pwgr/passwd_sample
|
||||
@@ -1,13 +1,13 @@
|
||||
root:x:b:0:
|
||||
root:x:0:0:root:/root:/bin/bash
|
||||
-bin:x:1:1:bin:/bin:/sbin/nologin
|
||||
-bin:x:-1:1:bin:/bin:/sbin/nologin
|
||||
+abin:x:1:1:bin:/bin:/sbin/nologin
|
||||
+bbin:x:-1:1:bin:/bin:/sbin/nologin
|
||||
uidonly:x:1::bin:/bin:/sbin/nologin
|
||||
::::1:1:bin:/bin:/sbin/nologin
|
||||
root:x:
|
||||
|
||||
#npt:*:66:77::/etc/ntp:/sbin/nologin
|
||||
-npt:*:66:77::/etc/ntp:/sbin/nologin
|
||||
-npt:*:66:77::/etc/ntp:/sbin/nologin:some:extra:context:added
|
||||
+anpt:*:66:77::/etc/ntp:/sbin/nologin
|
||||
+bnpt:*:66:77::/etc/ntp:/sbin/nologin:some:extra:context:added
|
||||
+npt:*::::/etc/ntp:/sbin/nologin
|
||||
-npt:*::::/etc/ntp:/sbin/nologin
|
||||
\ No newline at end of file
|
||||
diff --git a/test/cutils/utils_pwgr/utils_pwgr_ut.cc b/test/cutils/utils_pwgr/utils_pwgr_ut.cc
|
||||
index d856270d..1f3dab9e 100644
|
||||
--- a/test/cutils/utils_pwgr/utils_pwgr_ut.cc
|
||||
+++ b/test/cutils/utils_pwgr/utils_pwgr_ut.cc
|
||||
@@ -32,10 +32,10 @@ TEST(utils_pwgr, test_getpwent_r)
|
||||
|
||||
std::vector<std::tuple<std::string, std::string, int, int, std::string, std::string, std::string>> testcase = {
|
||||
std::make_tuple("root", "x", 0, 0, "root", "/root", "/bin/bash"),
|
||||
- std::make_tuple("bin", "x", 1, 1, "bin", "/bin", "/sbin/nologin"),
|
||||
- std::make_tuple("uidonly", "x", 1, 0, "bin", "/bin", "/sbin/nologin"),
|
||||
- std::make_tuple("npt", "*", 66, 77, "", "/etc/ntp", "/sbin/nologin"),
|
||||
- std::make_tuple("npt", "*", 66, 77, "", "/etc/ntp", "/sbin/nologin"),
|
||||
+ std::make_tuple("abin", "x", 1, 1, "bin", "/bin", "/sbin/nologin"),
|
||||
+ std::make_tuple("bbin", "x", 4294967295, 1, "bin", "/bin", "/sbin/nologin"),
|
||||
+ std::make_tuple("anpt", "*", 66, 77, "", "/etc/ntp", "/sbin/nologin"),
|
||||
+ std::make_tuple("bnpt", "*", 66, 77, "", "/etc/ntp", "/sbin/nologin:some:extra:context:added"),
|
||||
std::make_tuple("+npt", "*", 0, 0, "", "/etc/ntp", "/sbin/nologin"),
|
||||
std::make_tuple("-npt", "*", 0, 0, "", "/etc/ntp", "/sbin/nologin")
|
||||
};
|
||||
--
|
||||
2.20.1
|
||||
|
||||
@ -1,33 +0,0 @@
|
||||
From 3f02512d0b117839dce1ceb66208a96822fc7dd7 Mon Sep 17 00:00:00 2001
|
||||
From: haozi007 <liuhao27@huawei.com>
|
||||
Date: Mon, 16 May 2022 03:09:44 +0100
|
||||
Subject: [PATCH 16/16] add check result argument ut
|
||||
|
||||
Signed-off-by: haozi007 <liuhao27@huawei.com>
|
||||
---
|
||||
test/cutils/utils_pwgr/utils_pwgr_ut.cc | 2 ++
|
||||
1 file changed, 2 insertions(+)
|
||||
|
||||
diff --git a/test/cutils/utils_pwgr/utils_pwgr_ut.cc b/test/cutils/utils_pwgr/utils_pwgr_ut.cc
|
||||
index 1f3dab9e..90d09063 100644
|
||||
--- a/test/cutils/utils_pwgr/utils_pwgr_ut.cc
|
||||
+++ b/test/cutils/utils_pwgr/utils_pwgr_ut.cc
|
||||
@@ -44,6 +44,7 @@ TEST(utils_pwgr, test_getpwent_r)
|
||||
ASSERT_EQ(util_getpwent_r(f_pw, &pw, NULL, 0, &ppw), -1);
|
||||
ASSERT_EQ(util_getpwent_r(f_pw, &pw, invalid_buf, 1, &ppw), -1);
|
||||
ASSERT_EQ(util_getpwent_r(f_pw, &pw, buf, sizeof(buf), &ppw_alter), -1);
|
||||
+ ASSERT_EQ(util_getpwent_r(f_pw, &pw, buf, sizeof(buf), NULL), -1);
|
||||
|
||||
while (!feof(f_pw)) {
|
||||
(void)getc(f_pw);
|
||||
@@ -105,6 +106,7 @@ TEST(utils_pwgr, test_getgrent_r)
|
||||
ASSERT_EQ(util_getgrent_r(f_gr, &gr, NULL, 0, &pgr), -1);
|
||||
ASSERT_EQ(util_getgrent_r(f_gr, &gr, invalid_buf, 1, &pgr), -1);
|
||||
ASSERT_EQ(util_getgrent_r(f_gr, &gr, buf, sizeof(buf), &pgr_alter), -1);
|
||||
+ ASSERT_EQ(util_getgrent_r(f_gr, &gr, buf, sizeof(buf), NULL), -1);
|
||||
|
||||
while (!feof(f_gr)) {
|
||||
(void)getc(f_gr);
|
||||
--
|
||||
2.20.1
|
||||
|
||||
26
iSulad.spec
26
iSulad.spec
@ -1,5 +1,5 @@
|
||||
%global _version 2.0.13
|
||||
%global _release 5
|
||||
%global _version 2.0.14
|
||||
%global _release 1
|
||||
%global is_systemd 1
|
||||
%global enable_shimv2 1
|
||||
%global is_embedded 1
|
||||
@ -13,22 +13,6 @@ URL: https://gitee.com/openeuler/iSulad
|
||||
Source: https://gitee.com/openeuler/iSulad/repository/archive/v%{version}.tar.gz
|
||||
BuildRoot: {_tmppath}/iSulad-%{version}
|
||||
|
||||
Patch0001: 0001-cleancode-http-request.patch
|
||||
Patch0002: 0002-refactor-mount-parse-in-spec-module.patch
|
||||
Patch0003: 0003-support-isula-wait-even-if-it-s-not-oci-image.patch
|
||||
Patch0004: 0004-add-isula-import-restful-mode.patch
|
||||
Patch0005: 0005-Adapt-to-bionic-libc-parser-for-passwd-and-group-obj.patch
|
||||
Patch0006: 0006-test-adapt-to-the-enabled-selinux-host-environment.patch
|
||||
Patch0007: 0007-Adapt-to-bionic-libc-improve-lcov-coverage.patch
|
||||
Patch0008: 0008-fix-cmd-isulad-shim-module-encoding-problem.patch
|
||||
Patch0009: 0009-fix-utils-module-encoding-problem.patch
|
||||
Patch0010: 0010-clean-the-gRPC-client-module-code.patch
|
||||
Patch0011: 0011-remove-redundant-code.patch
|
||||
Patch0012: 0012-fix-coding-irregularities-of-entry-module.patch
|
||||
Patch0013: 0013-fix-coding-irregularities.patch
|
||||
Patch0014: 0014-fix-ut-bug-and-arguments-check.patch
|
||||
Patch0015: 0015-refactor-util_getgrent_r-and-util_getpwent_r.patch
|
||||
Patch0016: 0016-add-check-result-argument-ut.patch
|
||||
|
||||
%ifarch x86_64 aarch64
|
||||
Provides: libhttpclient.so()(64bit)
|
||||
@ -256,6 +240,12 @@ fi
|
||||
%endif
|
||||
|
||||
%changelog
|
||||
* Mon May 23 2022 haozi007 <liuhao27@huawei.com> - 2.0.14-1
|
||||
- Type: enhancement
|
||||
- ID: NA
|
||||
- SUG: NA
|
||||
- DESC: update version to v2.0.14
|
||||
|
||||
* Mon May 16 2022 haozi007<liuhao27@huawei.com> - 2.0.13-5
|
||||
- Type: enhancement
|
||||
- ID: NA
|
||||
|
||||
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user