summaryrefslogtreecommitdiff
path: root/ecp/server
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2024-05-22 19:12:20 +0200
committerUros Majstorovic <majstor@majstor.org>2024-05-22 19:12:20 +0200
commitea2bfa175c9fcc4c0d4aa708fea6ce497b2c73d6 (patch)
treec01244a35117da75790cdd034c47daa38bd4fc1f /ecp/server
parent34ab7d2f73d351158875effa175d2daf6a4ed976 (diff)
added line numbers feature to ecp util read key function
Diffstat (limited to 'ecp/server')
-rw-r--r--ecp/server/acl.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/ecp/server/acl.c b/ecp/server/acl.c
index 3341886..33b17ca 100644
--- a/ecp/server/acl.c
+++ b/ecp/server/acl.c
@@ -69,9 +69,9 @@ static int _add_key(ecp_ecdh_public_t *public, uint8_t roles) {
return ECP_OK;
}
-static int _read_file(int fd, ACLItem *head) {
+static int _read_file(int fd, ACLItem *head, int *line_cnt) {
ecp_ecdh_public_t public;
- int rv;
+ int _line_cnt, rv;
if (head == NULL) return ECP_ERR_ALLOC;
@@ -79,7 +79,7 @@ static int _read_file(int fd, ACLItem *head) {
head = head->next;
}
- while(ecp_util_read_key(fd, &public, NULL) == ECP_OK) {
+ while((rv = ecp_util_read_key(fd, &public, NULL, &_line_cnt)) == ECP_OK) {
if (head->key_cnt == ACL_MAX_KEY) {
head->next = acl_create_item();
if (head->next == NULL) return ECP_ERR_ALLOC;
@@ -87,9 +87,12 @@ static int _read_file(int fd, ACLItem *head) {
}
memcpy(&head->key[head->key_cnt], &public, sizeof(head->key[head->key_cnt]));
head->key_cnt++;
+ *line_cnt += _line_cnt;
}
+ *line_cnt += _line_cnt;
- return ECP_OK;
+ if (rv == ECP_ERR_EOF) return ECP_OK;
+ return rv;
}
static int _li2ht(ACLItem *head, int is_dir) {
@@ -194,6 +197,7 @@ int acl_load(void) {
ACLItem *acl_dir_new = NULL;
int fd = -1;
int fd_dir = -1;
+ int line_cnt;
int rv = ECP_OK;
int _rv;
@@ -202,7 +206,7 @@ int acl_load(void) {
if (srv_config->acl_fn) {
fd = open(srv_config->acl_fn, O_RDONLY);
if (fd < 0) {
- LOG(LOG_ERR, "acl_load: unable to open: %s\n", srv_config->acl_fn);
+ LOG(LOG_ERR, "acl_load: unable to open ACL file: %s\n", srv_config->acl_fn);
return ECP_ERR;
}
}
@@ -210,7 +214,7 @@ int acl_load(void) {
if (srv_config->acl_fn_dir) {
fd_dir = open(srv_config->acl_fn_dir, O_RDONLY);
if (fd_dir < 0) {
- LOG(LOG_ERR, "acl_load: unable to open: %s\n", srv_config->acl_fn_dir);
+ LOG(LOG_ERR, "acl_load: unable to open ACL file: %s\n", srv_config->acl_fn_dir);
close(fd);
return ECP_ERR;
}
@@ -218,20 +222,22 @@ int acl_load(void) {
pthread_mutex_lock(&acl_li_mutex);
if (fd >= 0) {
+ line_cnt = 0;
acl_new = acl_create_item();
- rv = _read_file(fd, acl_new);
+ rv = _read_file(fd, acl_new, &line_cnt);
if (rv) {
- LOG(LOG_ERR, "acl_load: read from file: %s err:%d\n", srv_config->acl_fn, rv);
+ LOG(LOG_ERR, "acl_load: bad ACL file: %s line:%d\n", srv_config->acl_fn, line_cnt);
acl_destroy_list(acl_new);
goto load_fin;
}
}
if (fd_dir >= 0) {
+ line_cnt = 0;
acl_dir_new = acl_create_item();
- rv = _read_file(fd_dir, acl_dir_new);
+ rv = _read_file(fd_dir, acl_dir_new, &line_cnt);
if (rv) {
- LOG(LOG_ERR, "acl_load: read from file: %s err:%d\n", srv_config->acl_fn_dir, rv);
+ LOG(LOG_ERR, "acl_load: bad ACL file: %s line:%d\n", srv_config->acl_fn_dir, line_cnt);
acl_destroy_list(acl_dir_new);
acl_destroy_list(acl_new);
goto load_fin;