mirror of
https://dev.iopsys.eu/bbf/bbfdm.git
synced 2025-12-10 07:44:39 +01:00
Optimize Device.Security. Object
This commit is contained in:
parent
09882ba799
commit
bd9f7db4fb
1 changed files with 29 additions and 21 deletions
|
|
@ -76,32 +76,46 @@ static char *generate_serial_number(const char *text, int length)
|
||||||
return hex;
|
return hex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int filter(const struct dirent *entry)
|
||||||
|
{
|
||||||
|
// Exclude hidden files and files not ending with ".0"
|
||||||
|
return (entry->d_name[0] != '.' && strstr(entry->d_name, ".0") != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int compare(const struct dirent **a, const struct dirent **b)
|
||||||
|
{
|
||||||
|
// Sort alphabetically (case-insensitive)
|
||||||
|
return strcasecmp((*a)->d_name, (*b)->d_name);
|
||||||
|
}
|
||||||
|
|
||||||
static int fill_certificate_paths(const char *dir_path, int *cidx)
|
static int fill_certificate_paths(const char *dir_path, int *cidx)
|
||||||
{
|
{
|
||||||
struct dirent *d_file = NULL;
|
struct dirent **namelist;
|
||||||
DIR *dir = NULL;
|
|
||||||
char cert_path[CERT_PATH_LEN];
|
|
||||||
|
|
||||||
sysfs_foreach_file(dir_path, dir, d_file) {
|
int num_files = scandir(dir_path, &namelist, filter, compare);
|
||||||
|
|
||||||
if (d_file->d_name[0] == '.' || !strstr(d_file->d_name, ".0"))
|
for (int i = 0; i < num_files; i++) {
|
||||||
|
char cert_path[CERT_PATH_LEN];
|
||||||
|
|
||||||
|
if (*cidx >= MAX_CERT) {
|
||||||
|
FREE(namelist[i]);
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (*cidx >= MAX_CERT)
|
snprintf(cert_path, sizeof(cert_path), "%s/%s", dir_path, namelist[i]->d_name);
|
||||||
break;
|
|
||||||
|
|
||||||
snprintf(cert_path, sizeof(cert_path), "%s/%s", dir_path, d_file->d_name);
|
if (!file_exists(cert_path) || !is_regular_file(cert_path)) {
|
||||||
|
FREE(namelist[i]);
|
||||||
if (!file_exists(cert_path) || !is_regular_file(cert_path))
|
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
DM_STRNCPY(certifcates_paths[*cidx], cert_path, CERT_PATH_LEN);
|
DM_STRNCPY(certifcates_paths[*cidx], cert_path, CERT_PATH_LEN);
|
||||||
(*cidx)++;
|
(*cidx)++;
|
||||||
|
|
||||||
|
FREE(namelist[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dir)
|
FREE(namelist);
|
||||||
closedir (dir);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -145,10 +159,9 @@ static int get_certificate_paths(void)
|
||||||
static int browseSecurityCertificateInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
|
static int browseSecurityCertificateInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
|
||||||
{
|
{
|
||||||
struct certificate_profile certificateprofile = {0};
|
struct certificate_profile certificateprofile = {0};
|
||||||
struct uci_section *dmmap_sec = NULL;
|
|
||||||
struct dm_data curr_data = {0};
|
struct dm_data curr_data = {0};
|
||||||
char *inst = NULL;
|
char *inst = NULL;
|
||||||
int i, status;
|
int i, status, id = 0;
|
||||||
|
|
||||||
get_certificate_paths();
|
get_certificate_paths();
|
||||||
|
|
||||||
|
|
@ -167,16 +180,11 @@ static int browseSecurityCertificateInst(struct dmctx *dmctx, DMNODE *parent_nod
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((dmmap_sec = get_dup_section_in_dmmap_opt("dmmap_security", "security_certificate", "path", certifcates_paths[i])) == NULL) {
|
|
||||||
dmuci_add_section_bbfdm("dmmap_security", "security_certificate", &dmmap_sec);
|
|
||||||
dmuci_set_value_by_section_bbfdm(dmmap_sec, "path", certifcates_paths[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
init_certificate(certifcates_paths[i], cert, &certificateprofile);
|
init_certificate(certifcates_paths[i], cert, &certificateprofile);
|
||||||
|
|
||||||
curr_data.additional_data = (void *)&certificateprofile;
|
curr_data.additional_data = (void *)&certificateprofile;
|
||||||
|
|
||||||
inst = handle_instance(dmctx, parent_node, dmmap_sec, "security_certificate_instance", "security_certificate_alias");
|
inst = handle_instance_without_section(dmctx, parent_node, ++id);
|
||||||
|
|
||||||
status = DM_LINK_INST_OBJ(dmctx, parent_node, &curr_data, inst);
|
status = DM_LINK_INST_OBJ(dmctx, parent_node, &curr_data, inst);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue