Skip to content

Commit

Permalink
libselinux: rename hashtab functions
Browse files Browse the repository at this point in the history
In commit d95bc8b ("libselinux: migrating hashtab from
policycoreutils") and commit 4a42050 ("libselinux: adapting hashtab
to libselinux"), the hashtab implementation was copied to libselinux.
Since the same functions exist in libsepol (e.g., hashtab_create,
hashtab_destroy, etc), a compilation error is raised when both libraries
are included statically.

Prefix the libselinux internal implementation with "selinux_".

Signed-off-by: Thiébaud Weksteen <tweek@google.com>
Acked-by: James Carter <jwcart2@gmail.com>
  • Loading branch information
tweksteen authored and jwcart2 committed Sep 4, 2024
1 parent 9c7c6e1 commit b411742
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
16 changes: 8 additions & 8 deletions libselinux/src/hashtab.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <string.h>
#include "hashtab.h"

hashtab_t hashtab_create(unsigned int (*hash_value) (hashtab_t h,
hashtab_t selinux_hashtab_create(unsigned int (*hash_value) (hashtab_t h,
const_hashtab_key_t key),
int (*keycmp) (hashtab_t h,
const_hashtab_key_t key1,
Expand Down Expand Up @@ -42,7 +42,7 @@ hashtab_t hashtab_create(unsigned int (*hash_value) (hashtab_t h,
return p;
}

int hashtab_insert(hashtab_t h, hashtab_key_t key, hashtab_datum_t datum)
int selinux_hashtab_insert(hashtab_t h, hashtab_key_t key, hashtab_datum_t datum)
{
unsigned int hvalue;
hashtab_ptr_t prev, cur, newnode;
Expand Down Expand Up @@ -79,7 +79,7 @@ int hashtab_insert(hashtab_t h, hashtab_key_t key, hashtab_datum_t datum)
return HASHTAB_SUCCESS;
}

int hashtab_remove(hashtab_t h, hashtab_key_t key,
int selinux_hashtab_remove(hashtab_t h, hashtab_key_t key,
void (*destroy) (hashtab_key_t k,
hashtab_datum_t d, void *args), void *args)
{
Expand Down Expand Up @@ -112,7 +112,7 @@ int hashtab_remove(hashtab_t h, hashtab_key_t key,
return HASHTAB_SUCCESS;
}

hashtab_datum_t hashtab_search(hashtab_t h, const_hashtab_key_t key)
hashtab_datum_t selinux_hashtab_search(hashtab_t h, const_hashtab_key_t key)
{

unsigned int hvalue;
Expand All @@ -132,7 +132,7 @@ hashtab_datum_t hashtab_search(hashtab_t h, const_hashtab_key_t key)
return cur->datum;
}

void hashtab_destroy(hashtab_t h)
void selinux_hashtab_destroy(hashtab_t h)
{
unsigned int i;
hashtab_ptr_t cur, temp;
Expand All @@ -156,7 +156,7 @@ void hashtab_destroy(hashtab_t h)
free(h);
}

void hashtab_destroy_key(hashtab_t h,
void selinux_hashtab_destroy_key(hashtab_t h,
int (*destroy_key) (hashtab_key_t k))
{
unsigned int i;
Expand All @@ -182,7 +182,7 @@ void hashtab_destroy_key(hashtab_t h,
free(h);
}

int hashtab_map(hashtab_t h,
int selinux_hashtab_map(hashtab_t h,
int (*apply) (hashtab_key_t k,
hashtab_datum_t d, void *args), void *args)
{
Expand All @@ -205,7 +205,7 @@ int hashtab_map(hashtab_t h,
return HASHTAB_SUCCESS;
}

void hashtab_hash_eval(hashtab_t h, char *tag)
void selinux_hashtab_hash_eval(hashtab_t h, char *tag)
{
unsigned int i;
int chain_len, slots_used, max_chain_len;
Expand Down
16 changes: 8 additions & 8 deletions libselinux/src/hashtab.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ typedef hashtab_val_t *hashtab_t;
Returns NULL if insufficient space is available or
the new hash table otherwise.
*/
extern hashtab_t hashtab_create(unsigned int (*hash_value) (hashtab_t h,
extern hashtab_t selinux_hashtab_create(unsigned int (*hash_value) (hashtab_t h,
const_hashtab_key_t
key),
int (*keycmp) (hashtab_t h,
Expand All @@ -66,7 +66,7 @@ extern hashtab_t hashtab_create(unsigned int (*hash_value) (hashtab_t h,
HASHTAB_PRESENT if there is already an entry with the same key or
HASHTAB_SUCCESS otherwise.
*/
extern int hashtab_insert(hashtab_t h, hashtab_key_t k, hashtab_datum_t d);
extern int selinux_hashtab_insert(hashtab_t h, hashtab_key_t k, hashtab_datum_t d);

/*
Removes the entry with the specified key from the hash table.
Expand All @@ -76,7 +76,7 @@ extern int hashtab_insert(hashtab_t h, hashtab_key_t k, hashtab_datum_t d);
Returns HASHTAB_MISSING if no entry has the specified key or
HASHTAB_SUCCESS otherwise.
*/
extern int hashtab_remove(hashtab_t h, hashtab_key_t k,
extern int selinux_hashtab_remove(hashtab_t h, hashtab_key_t k,
void (*destroy) (hashtab_key_t k,
hashtab_datum_t d,
void *args), void *args);
Expand All @@ -87,13 +87,13 @@ extern int hashtab_remove(hashtab_t h, hashtab_key_t k,
Returns NULL if no entry has the specified key or
the datum of the entry otherwise.
*/
extern hashtab_datum_t hashtab_search(hashtab_t h, const_hashtab_key_t k);
extern hashtab_datum_t selinux_hashtab_search(hashtab_t h, const_hashtab_key_t k);

/*
Destroys the specified hash table.
*/
extern void hashtab_destroy(hashtab_t h);
extern void hashtab_destroy_key(hashtab_t h,
extern void selinux_hashtab_destroy(hashtab_t h);
extern void selinux_hashtab_destroy_key(hashtab_t h,
int (*destroy_key) (hashtab_key_t k));

/*
Expand All @@ -107,11 +107,11 @@ extern void hashtab_destroy_key(hashtab_t h,
iterating through the hash table and will propagate the error
return to its caller.
*/
extern int hashtab_map(hashtab_t h,
extern int selinux_hashtab_map(hashtab_t h,
int (*apply) (hashtab_key_t k,
hashtab_datum_t d,
void *args), void *args);

extern void hashtab_hash_eval(hashtab_t h, char *tag);
extern void selinux_hashtab_hash_eval(hashtab_t h, char *tag);

#endif
10 changes: 5 additions & 5 deletions libselinux/src/label_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ static int nodups_specs(struct saved_data *data, const char *path)
struct chkdups_key *new = NULL;
unsigned int hashtab_len = (data->nspec / SHRINK_MULTIS) ? data->nspec / SHRINK_MULTIS : 1;

hashtab_t hash_table = hashtab_create(symhash, symcmp, hashtab_len);
hashtab_t hash_table = selinux_hashtab_create(symhash, symcmp, hashtab_len);
if (!hash_table) {
rc = -1;
COMPAT_LOG(SELINUX_ERROR, "%s: hashtab create failed.\n", path);
Expand All @@ -121,18 +121,18 @@ static int nodups_specs(struct saved_data *data, const char *path)
new = (struct chkdups_key *)malloc(sizeof(struct chkdups_key));
if (!new) {
rc = -1;
hashtab_destroy_key(hash_table, destroy_chkdups_key);
selinux_hashtab_destroy_key(hash_table, destroy_chkdups_key);
COMPAT_LOG(SELINUX_ERROR, "%s: hashtab key create failed.\n", path);
return rc;
}
new->regex = spec_arr[ii].regex_str;
new->mode = spec_arr[ii].mode;
ret = hashtab_insert(hash_table, (hashtab_key_t)new, &spec_arr[ii]);
ret = selinux_hashtab_insert(hash_table, (hashtab_key_t)new, &spec_arr[ii]);
if (ret == HASHTAB_SUCCESS)
continue;
if (ret == HASHTAB_PRESENT) {
curr_spec =
(struct spec *)hashtab_search(hash_table, (hashtab_key_t)new);
(struct spec *)selinux_hashtab_search(hash_table, (hashtab_key_t)new);
rc = -1;
errno = EINVAL;
free(new);
Expand Down Expand Up @@ -161,7 +161,7 @@ static int nodups_specs(struct saved_data *data, const char *path)
}
}

hashtab_destroy_key(hash_table, destroy_chkdups_key);
selinux_hashtab_destroy_key(hash_table, destroy_chkdups_key);

return rc;
}
Expand Down

0 comments on commit b411742

Please sign in to comment.