smartcard/fs: fix dir handling features a bit
This commit is contained in:
parent
e98480a6c9
commit
9272eff823
|
@ -72,7 +72,13 @@ int nsl_smartcard_file_delete(struct nsl_smartcard_file *file)
|
|||
if (!nsl_smartcard_is_file(file)) {
|
||||
return NSL_SMARTCARD_ERROR_WRONG_TYPE;
|
||||
}
|
||||
return nsl_smartcard_dir_delete(file->parent, file->id);
|
||||
file->flags &= ~NSL_SMARTCARD_FILE_FLAG_USED;
|
||||
if (file->flags & NSL_SMARTCARD_FILE_FLAG_ALLOCATED) {
|
||||
free(file->contents.file.data);
|
||||
}
|
||||
file->contents.file.data = NULL;
|
||||
file->contents.file.len = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -162,6 +168,22 @@ int nsl_smartcard_dir_init(struct nsl_smartcard_file *file, nsl_smartcart_file_i
|
|||
return 0;
|
||||
}
|
||||
|
||||
int nsl_smartcard_dir_delete(struct nsl_smartcard_file *file)
|
||||
{
|
||||
if (!nsl_smartcard_is_dir(file)) {
|
||||
return NSL_SMARTCARD_ERROR_WRONG_TYPE;
|
||||
}
|
||||
|
||||
int err = nsl_smartcard_dir_clear(file);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
file->flags &= ~NSL_SMARTCARD_FILE_FLAG_USED;
|
||||
file->contents.dir.auth = NSL_SMARTCARD_AUTH_NONE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nsl_smartcard_dir_authorize(struct nsl_smartcard_file *file, const uint8_t *pin, size_t len, enum nsl_smartcard_auth_level level)
|
||||
{
|
||||
if (!nsl_smartcard_is_dir(file)) {
|
||||
|
@ -298,7 +320,7 @@ int nsl_smartcard_dir_find(struct nsl_smartcard_file *file, nsl_smartcart_file_i
|
|||
return NSL_SMARTCARD_ERROR_NOT_FOUND;
|
||||
}
|
||||
|
||||
int nsl_smartcard_dir_delete(struct nsl_smartcard_file *file, nsl_smartcart_file_id_t id)
|
||||
int nsl_smartcard_dir_remove(struct nsl_smartcard_file *file, nsl_smartcart_file_id_t id)
|
||||
{
|
||||
if (!nsl_smartcard_is_dir(file)) {
|
||||
return NSL_SMARTCARD_ERROR_WRONG_TYPE;
|
||||
|
@ -323,10 +345,6 @@ int nsl_smartcard_dir_delete(struct nsl_smartcard_file *file, nsl_smartcart_file
|
|||
|
||||
child->parent = NULL;
|
||||
child->prev = child->next = NULL;
|
||||
child->flags &= ~NSL_SMARTCARD_FILE_FLAG_USED;
|
||||
if (child->flags & NSL_SMARTCARD_FILE_FLAG_ALLOCATED) {
|
||||
free(child);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -339,15 +357,25 @@ int nsl_smartcard_dir_clear(struct nsl_smartcard_file *file)
|
|||
return NSL_SMARTCARD_ERROR_UNAUTHORIZED;
|
||||
}
|
||||
|
||||
struct nsl_smartcard_file *f = file->contents.dir.children, *next;
|
||||
while (f) {
|
||||
next = f->next;
|
||||
if (nsl_smartcard_is_dir(f)) {
|
||||
nsl_smartcard_dir_clear(f);
|
||||
struct nsl_smartcard_file *child = file->contents.dir.children, *next;
|
||||
while (child) {
|
||||
next = child->next;
|
||||
nsl_smartcard_dir_remove(file, child->id);
|
||||
if (nsl_smartcard_is_dir(child)) {
|
||||
nsl_smartcard_dir_delete(child);
|
||||
} else {
|
||||
nsl_smartcard_file_delete(f);
|
||||
nsl_smartcard_file_delete(child);
|
||||
}
|
||||
f = next;
|
||||
child = next;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nsl_smartcard_dir_iter(struct nsl_smartcard_file *file, struct nsl_smartcard_file **child)
|
||||
{
|
||||
if (!nsl_smartcard_is_dir(file)) {
|
||||
return NSL_SMARTCARD_ERROR_WRONG_TYPE;
|
||||
}
|
||||
*child = file->contents.dir.children;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -100,8 +100,8 @@ struct nsl_smartcard_handle
|
|||
|
||||
|
||||
int nsl_smartcard_file_init(struct nsl_smartcard_file *, nsl_smartcart_file_id_t id, enum nsl_smartcard_file_type type);
|
||||
int nsl_smartcard_file_open(struct nsl_smartcard_file *, struct nsl_smartcard_handle *handle);
|
||||
int nsl_smartcard_file_delete(struct nsl_smartcard_file *);
|
||||
int nsl_smartcard_file_open(struct nsl_smartcard_file *, struct nsl_smartcard_handle *handle);
|
||||
|
||||
static inline int nsl_smartcard_handle_is_valid(struct nsl_smartcard_handle *handle)
|
||||
{
|
||||
|
@ -115,6 +115,7 @@ int nsl_smartcard_handle_tell(struct nsl_smartcard_handle *, size_t *pos);
|
|||
int nsl_smartcard_handle_close(struct nsl_smartcard_handle *);
|
||||
|
||||
int nsl_smartcard_dir_init(struct nsl_smartcard_file *, nsl_smartcart_file_id_t id);
|
||||
int nsl_smartcard_dir_delete(struct nsl_smartcard_file *);
|
||||
int nsl_smartcard_dir_authorize(struct nsl_smartcard_file *, const uint8_t *pin, size_t len, enum nsl_smartcard_auth_level level);
|
||||
int nsl_smartcard_dir_change_pin(struct nsl_smartcard_file *, const uint8_t *pin, size_t len, enum nsl_smartcard_auth_level level);
|
||||
int nsl_smartcard_dir_internal_begin(struct nsl_smartcard_file *);
|
||||
|
@ -122,5 +123,6 @@ int nsl_smartcard_dir_internal_end(struct nsl_smartcard_file *);
|
|||
|
||||
int nsl_smartcard_dir_add(struct nsl_smartcard_file *, struct nsl_smartcard_file *child);
|
||||
int nsl_smartcard_dir_find(struct nsl_smartcard_file *, nsl_smartcart_file_id_t id, struct nsl_smartcard_file **child);
|
||||
int nsl_smartcard_dir_delete(struct nsl_smartcard_file *, nsl_smartcart_file_id_t id);
|
||||
int nsl_smartcard_dir_remove(struct nsl_smartcard_file *, nsl_smartcart_file_id_t id);
|
||||
int nsl_smartcard_dir_clear(struct nsl_smartcard_file *);
|
||||
int nsl_smartcard_dir_iter(struct nsl_smartcard_file *, struct nsl_smartcard_file **child);
|
||||
|
|
Loading…
Reference in New Issue