Define common function for recursive scanning
Signed-off-by: Dmitry Kasatkin <d.kasatkin@samsung.com>
This commit is contained in:
parent
92033dc404
commit
4d7d2c71a5
83
src/evmctl.c
83
src/evmctl.c
@ -576,12 +576,12 @@ static int get_file_type(const char *path, const char *search_type)
|
|||||||
return dts;
|
return dts;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cmd_hash_ima(struct command *cmd)
|
static int do_cmd(struct command *cmd, find_cb_t func)
|
||||||
{
|
{
|
||||||
char *file = g_argv[optind++];
|
char *path = g_argv[optind++];
|
||||||
int err, dts = REG_MASK; /* only regular files by default */
|
int err, dts = REG_MASK; /* only regular files by default */
|
||||||
|
|
||||||
if (!file) {
|
if (!path) {
|
||||||
log_err("Parameters missing\n");
|
log_err("Parameters missing\n");
|
||||||
print_usage(cmd);
|
print_usage(cmd);
|
||||||
return -1;
|
return -1;
|
||||||
@ -589,18 +589,23 @@ static int cmd_hash_ima(struct command *cmd)
|
|||||||
|
|
||||||
if (recursive) {
|
if (recursive) {
|
||||||
if (search_type) {
|
if (search_type) {
|
||||||
dts = get_file_type(file, search_type);
|
dts = get_file_type(path, search_type);
|
||||||
if (dts < 0)
|
if (dts < 0)
|
||||||
return dts;
|
return dts;
|
||||||
}
|
}
|
||||||
err = find(file, dts, hash_ima);
|
err = find(path, dts, func);
|
||||||
} else {
|
} else {
|
||||||
err = hash_ima(file);
|
err = func(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int cmd_hash_ima(struct command *cmd)
|
||||||
|
{
|
||||||
|
return do_cmd(cmd, hash_ima);
|
||||||
|
}
|
||||||
|
|
||||||
static int sign_ima_file(const char *file)
|
static int sign_ima_file(const char *file)
|
||||||
{
|
{
|
||||||
char *key;
|
char *key;
|
||||||
@ -612,27 +617,7 @@ static int sign_ima_file(const char *file)
|
|||||||
|
|
||||||
static int cmd_sign_ima(struct command *cmd)
|
static int cmd_sign_ima(struct command *cmd)
|
||||||
{
|
{
|
||||||
char *file = g_argv[optind++];
|
return do_cmd(cmd, sign_ima_file);
|
||||||
int err, dts = REG_MASK; /* only regular files by default */
|
|
||||||
|
|
||||||
if (!file) {
|
|
||||||
log_err("Parameters missing\n");
|
|
||||||
print_usage(cmd);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (recursive) {
|
|
||||||
if (search_type) {
|
|
||||||
dts = get_file_type(file, search_type);
|
|
||||||
if (dts < 0)
|
|
||||||
return dts;
|
|
||||||
}
|
|
||||||
err = find(file, dts, sign_ima_file);
|
|
||||||
} else {
|
|
||||||
err = sign_ima_file(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cmd_sign_hash(struct command *cmd)
|
static int cmd_sign_hash(struct command *cmd)
|
||||||
@ -702,27 +687,7 @@ static int sign_evm_path(const char *file)
|
|||||||
|
|
||||||
static int cmd_sign_evm(struct command *cmd)
|
static int cmd_sign_evm(struct command *cmd)
|
||||||
{
|
{
|
||||||
char *path = g_argv[optind++];
|
return do_cmd(cmd, sign_evm_path);
|
||||||
int err, dts = REG_MASK; /* only regular files by default */
|
|
||||||
|
|
||||||
if (!path) {
|
|
||||||
log_err("Parameters missing\n");
|
|
||||||
print_usage(cmd);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (recursive) {
|
|
||||||
if (search_type) {
|
|
||||||
dts = get_file_type(path, search_type);
|
|
||||||
if (dts < 0)
|
|
||||||
return dts;
|
|
||||||
}
|
|
||||||
err = find(path, dts, sign_evm_path);
|
|
||||||
} else {
|
|
||||||
err = sign_evm_path(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int verify_evm(const char *file)
|
static int verify_evm(const char *file)
|
||||||
@ -1153,27 +1118,7 @@ static int find(const char *path, int dts, find_cb_t func)
|
|||||||
|
|
||||||
static int cmd_ima_fix(struct command *cmd)
|
static int cmd_ima_fix(struct command *cmd)
|
||||||
{
|
{
|
||||||
char *path = g_argv[optind++];
|
return do_cmd(cmd, ima_fix);
|
||||||
int err, dts = REG_MASK; /* only regular files by default */
|
|
||||||
|
|
||||||
if (!path) {
|
|
||||||
log_err("Parameters missing\n");
|
|
||||||
print_usage(cmd);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (recursive) {
|
|
||||||
if (search_type) {
|
|
||||||
dts = get_file_type(path, search_type);
|
|
||||||
if (dts < 0)
|
|
||||||
return dts;
|
|
||||||
}
|
|
||||||
err = find(path, dts, ima_fix);
|
|
||||||
} else {
|
|
||||||
err = ima_fix(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user