Message ID | 20230814132025.45364-8-cgzones@googlemail.com (mailing list archive) |
---|---|
State | Accepted |
Commit | b4007663c5ec |
Delegated to: | Petr Lautrbach |
Headers | show |
Series | libselinux: rework selabel_file(5) database | expand |
On Mon, Aug 14, 2023 at 9:42 AM Christian Göttsche <cgzones@googlemail.com> wrote: > > Comparing two selabel handles should (and currently does) not modify > them. > > Signed-off-by: Christian Göttsche <cgzones@googlemail.com> Acked-by: James Carter <jwcart2@gmail.com> > --- > libselinux/include/selinux/label.h | 4 ++-- > libselinux/src/label.c | 4 ++-- > libselinux/src/label_file.c | 22 +++++++++++----------- > libselinux/src/label_internal.h | 4 ++-- > 4 files changed, 17 insertions(+), 17 deletions(-) > > diff --git a/libselinux/include/selinux/label.h b/libselinux/include/selinux/label.h > index e8983606..ce189a3a 100644 > --- a/libselinux/include/selinux/label.h > +++ b/libselinux/include/selinux/label.h > @@ -153,8 +153,8 @@ enum selabel_cmp_result { > * if @h1 is identical to @h2, %SELABEL_SUPERSET if @h1 is a superset > * of @h2, and %SELABEL_INCOMPARABLE if @h1 and @h2 are incomparable. > */ > -extern enum selabel_cmp_result selabel_cmp(struct selabel_handle *h1, > - struct selabel_handle *h2); > +extern enum selabel_cmp_result selabel_cmp(const struct selabel_handle *h1, > + const struct selabel_handle *h2); > > /** > * selabel_stats - log labeling operation statistics. > diff --git a/libselinux/src/label.c b/libselinux/src/label.c > index a2efa99c..c0f586a2 100644 > --- a/libselinux/src/label.c > +++ b/libselinux/src/label.c > @@ -333,8 +333,8 @@ int selabel_lookup_best_match_raw(struct selabel_handle *rec, char **con, > return *con ? 0 : -1; > } > > -enum selabel_cmp_result selabel_cmp(struct selabel_handle *h1, > - struct selabel_handle *h2) > +enum selabel_cmp_result selabel_cmp(const struct selabel_handle *h1, > + const struct selabel_handle *h2) > { > if (!h1->func_cmp || h1->func_cmp != h2->func_cmp) > return SELABEL_INCOMPARABLE; > diff --git a/libselinux/src/label_file.c b/libselinux/src/label_file.c > index 461abc61..5ac23e1f 100644 > --- a/libselinux/src/label_file.c > +++ b/libselinux/src/label_file.c > @@ -1237,7 +1237,7 @@ out: > return lr; > } > > -static enum selabel_cmp_result incomp(struct spec *spec1, struct spec *spec2, const char *reason, int i, int j) > +static enum selabel_cmp_result incomp(const struct spec *spec1, const struct spec *spec2, const char *reason, int i, int j) > { > selinux_log(SELINUX_INFO, > "selabel_cmp: mismatched %s on entry %d: (%s, %x, %s) vs entry %d: (%s, %x, %s)\n", > @@ -1247,21 +1247,21 @@ static enum selabel_cmp_result incomp(struct spec *spec1, struct spec *spec2, co > return SELABEL_INCOMPARABLE; > } > > -static enum selabel_cmp_result cmp(struct selabel_handle *h1, > - struct selabel_handle *h2) > +static enum selabel_cmp_result cmp(const struct selabel_handle *h1, > + const struct selabel_handle *h2) > { > - struct saved_data *data1 = (struct saved_data *)h1->data; > - struct saved_data *data2 = (struct saved_data *)h2->data; > + const struct saved_data *data1 = (const struct saved_data *)h1->data; > + const struct saved_data *data2 = (const struct saved_data *)h2->data; > unsigned int i, nspec1 = data1->nspec, j, nspec2 = data2->nspec; > - struct spec *spec_arr1 = data1->spec_arr, *spec_arr2 = data2->spec_arr; > - struct stem *stem_arr1 = data1->stem_arr, *stem_arr2 = data2->stem_arr; > + const struct spec *spec_arr1 = data1->spec_arr, *spec_arr2 = data2->spec_arr; > + const struct stem *stem_arr1 = data1->stem_arr, *stem_arr2 = data2->stem_arr; > bool skipped1 = false, skipped2 = false; > > i = 0; > j = 0; > while (i < nspec1 && j < nspec2) { > - struct spec *spec1 = &spec_arr1[i]; > - struct spec *spec2 = &spec_arr2[j]; > + const struct spec *spec1 = &spec_arr1[i]; > + const struct spec *spec2 = &spec_arr2[j]; > > /* > * Because sort_specs() moves exact pathnames to the > @@ -1297,8 +1297,8 @@ static enum selabel_cmp_result cmp(struct selabel_handle *h1, > if (spec2->stem_id == -1 && spec1->stem_id != -1) > return incomp(spec1, spec2, "stem_id", i, j); > if (spec1->stem_id != -1 && spec2->stem_id != -1) { > - struct stem *stem1 = &stem_arr1[spec1->stem_id]; > - struct stem *stem2 = &stem_arr2[spec2->stem_id]; > + const struct stem *stem1 = &stem_arr1[spec1->stem_id]; > + const struct stem *stem2 = &stem_arr2[spec2->stem_id]; > if (stem1->len != stem2->len || > strncmp(stem1->buf, stem2->buf, stem1->len)) > return incomp(spec1, spec2, "stem", i, j); > diff --git a/libselinux/src/label_internal.h b/libselinux/src/label_internal.h > index 273a630a..bc5a6928 100644 > --- a/libselinux/src/label_internal.h > +++ b/libselinux/src/label_internal.h > @@ -98,8 +98,8 @@ struct selabel_handle { > const char *key, > const char **aliases, > int type); > - enum selabel_cmp_result (*func_cmp)(struct selabel_handle *h1, > - struct selabel_handle *h2); > + enum selabel_cmp_result (*func_cmp)(const struct selabel_handle *h1, > + const struct selabel_handle *h2); > > /* supports backend-specific state information */ > void *data; > -- > 2.40.1 >
On Mon, Oct 2, 2023 at 2:11 PM James Carter <jwcart2@gmail.com> wrote: > > On Mon, Aug 14, 2023 at 9:42 AM Christian Göttsche > <cgzones@googlemail.com> wrote: > > > > Comparing two selabel handles should (and currently does) not modify > > them. > > > > Signed-off-by: Christian Göttsche <cgzones@googlemail.com> > > Acked-by: James Carter <jwcart2@gmail.com> > Merged. Thanks, Jim > > --- > > libselinux/include/selinux/label.h | 4 ++-- > > libselinux/src/label.c | 4 ++-- > > libselinux/src/label_file.c | 22 +++++++++++----------- > > libselinux/src/label_internal.h | 4 ++-- > > 4 files changed, 17 insertions(+), 17 deletions(-) > > > > diff --git a/libselinux/include/selinux/label.h b/libselinux/include/selinux/label.h > > index e8983606..ce189a3a 100644 > > --- a/libselinux/include/selinux/label.h > > +++ b/libselinux/include/selinux/label.h > > @@ -153,8 +153,8 @@ enum selabel_cmp_result { > > * if @h1 is identical to @h2, %SELABEL_SUPERSET if @h1 is a superset > > * of @h2, and %SELABEL_INCOMPARABLE if @h1 and @h2 are incomparable. > > */ > > -extern enum selabel_cmp_result selabel_cmp(struct selabel_handle *h1, > > - struct selabel_handle *h2); > > +extern enum selabel_cmp_result selabel_cmp(const struct selabel_handle *h1, > > + const struct selabel_handle *h2); > > > > /** > > * selabel_stats - log labeling operation statistics. > > diff --git a/libselinux/src/label.c b/libselinux/src/label.c > > index a2efa99c..c0f586a2 100644 > > --- a/libselinux/src/label.c > > +++ b/libselinux/src/label.c > > @@ -333,8 +333,8 @@ int selabel_lookup_best_match_raw(struct selabel_handle *rec, char **con, > > return *con ? 0 : -1; > > } > > > > -enum selabel_cmp_result selabel_cmp(struct selabel_handle *h1, > > - struct selabel_handle *h2) > > +enum selabel_cmp_result selabel_cmp(const struct selabel_handle *h1, > > + const struct selabel_handle *h2) > > { > > if (!h1->func_cmp || h1->func_cmp != h2->func_cmp) > > return SELABEL_INCOMPARABLE; > > diff --git a/libselinux/src/label_file.c b/libselinux/src/label_file.c > > index 461abc61..5ac23e1f 100644 > > --- a/libselinux/src/label_file.c > > +++ b/libselinux/src/label_file.c > > @@ -1237,7 +1237,7 @@ out: > > return lr; > > } > > > > -static enum selabel_cmp_result incomp(struct spec *spec1, struct spec *spec2, const char *reason, int i, int j) > > +static enum selabel_cmp_result incomp(const struct spec *spec1, const struct spec *spec2, const char *reason, int i, int j) > > { > > selinux_log(SELINUX_INFO, > > "selabel_cmp: mismatched %s on entry %d: (%s, %x, %s) vs entry %d: (%s, %x, %s)\n", > > @@ -1247,21 +1247,21 @@ static enum selabel_cmp_result incomp(struct spec *spec1, struct spec *spec2, co > > return SELABEL_INCOMPARABLE; > > } > > > > -static enum selabel_cmp_result cmp(struct selabel_handle *h1, > > - struct selabel_handle *h2) > > +static enum selabel_cmp_result cmp(const struct selabel_handle *h1, > > + const struct selabel_handle *h2) > > { > > - struct saved_data *data1 = (struct saved_data *)h1->data; > > - struct saved_data *data2 = (struct saved_data *)h2->data; > > + const struct saved_data *data1 = (const struct saved_data *)h1->data; > > + const struct saved_data *data2 = (const struct saved_data *)h2->data; > > unsigned int i, nspec1 = data1->nspec, j, nspec2 = data2->nspec; > > - struct spec *spec_arr1 = data1->spec_arr, *spec_arr2 = data2->spec_arr; > > - struct stem *stem_arr1 = data1->stem_arr, *stem_arr2 = data2->stem_arr; > > + const struct spec *spec_arr1 = data1->spec_arr, *spec_arr2 = data2->spec_arr; > > + const struct stem *stem_arr1 = data1->stem_arr, *stem_arr2 = data2->stem_arr; > > bool skipped1 = false, skipped2 = false; > > > > i = 0; > > j = 0; > > while (i < nspec1 && j < nspec2) { > > - struct spec *spec1 = &spec_arr1[i]; > > - struct spec *spec2 = &spec_arr2[j]; > > + const struct spec *spec1 = &spec_arr1[i]; > > + const struct spec *spec2 = &spec_arr2[j]; > > > > /* > > * Because sort_specs() moves exact pathnames to the > > @@ -1297,8 +1297,8 @@ static enum selabel_cmp_result cmp(struct selabel_handle *h1, > > if (spec2->stem_id == -1 && spec1->stem_id != -1) > > return incomp(spec1, spec2, "stem_id", i, j); > > if (spec1->stem_id != -1 && spec2->stem_id != -1) { > > - struct stem *stem1 = &stem_arr1[spec1->stem_id]; > > - struct stem *stem2 = &stem_arr2[spec2->stem_id]; > > + const struct stem *stem1 = &stem_arr1[spec1->stem_id]; > > + const struct stem *stem2 = &stem_arr2[spec2->stem_id]; > > if (stem1->len != stem2->len || > > strncmp(stem1->buf, stem2->buf, stem1->len)) > > return incomp(spec1, spec2, "stem", i, j); > > diff --git a/libselinux/src/label_internal.h b/libselinux/src/label_internal.h > > index 273a630a..bc5a6928 100644 > > --- a/libselinux/src/label_internal.h > > +++ b/libselinux/src/label_internal.h > > @@ -98,8 +98,8 @@ struct selabel_handle { > > const char *key, > > const char **aliases, > > int type); > > - enum selabel_cmp_result (*func_cmp)(struct selabel_handle *h1, > > - struct selabel_handle *h2); > > + enum selabel_cmp_result (*func_cmp)(const struct selabel_handle *h1, > > + const struct selabel_handle *h2); > > > > /* supports backend-specific state information */ > > void *data; > > -- > > 2.40.1 > >
diff --git a/libselinux/include/selinux/label.h b/libselinux/include/selinux/label.h index e8983606..ce189a3a 100644 --- a/libselinux/include/selinux/label.h +++ b/libselinux/include/selinux/label.h @@ -153,8 +153,8 @@ enum selabel_cmp_result { * if @h1 is identical to @h2, %SELABEL_SUPERSET if @h1 is a superset * of @h2, and %SELABEL_INCOMPARABLE if @h1 and @h2 are incomparable. */ -extern enum selabel_cmp_result selabel_cmp(struct selabel_handle *h1, - struct selabel_handle *h2); +extern enum selabel_cmp_result selabel_cmp(const struct selabel_handle *h1, + const struct selabel_handle *h2); /** * selabel_stats - log labeling operation statistics. diff --git a/libselinux/src/label.c b/libselinux/src/label.c index a2efa99c..c0f586a2 100644 --- a/libselinux/src/label.c +++ b/libselinux/src/label.c @@ -333,8 +333,8 @@ int selabel_lookup_best_match_raw(struct selabel_handle *rec, char **con, return *con ? 0 : -1; } -enum selabel_cmp_result selabel_cmp(struct selabel_handle *h1, - struct selabel_handle *h2) +enum selabel_cmp_result selabel_cmp(const struct selabel_handle *h1, + const struct selabel_handle *h2) { if (!h1->func_cmp || h1->func_cmp != h2->func_cmp) return SELABEL_INCOMPARABLE; diff --git a/libselinux/src/label_file.c b/libselinux/src/label_file.c index 461abc61..5ac23e1f 100644 --- a/libselinux/src/label_file.c +++ b/libselinux/src/label_file.c @@ -1237,7 +1237,7 @@ out: return lr; } -static enum selabel_cmp_result incomp(struct spec *spec1, struct spec *spec2, const char *reason, int i, int j) +static enum selabel_cmp_result incomp(const struct spec *spec1, const struct spec *spec2, const char *reason, int i, int j) { selinux_log(SELINUX_INFO, "selabel_cmp: mismatched %s on entry %d: (%s, %x, %s) vs entry %d: (%s, %x, %s)\n", @@ -1247,21 +1247,21 @@ static enum selabel_cmp_result incomp(struct spec *spec1, struct spec *spec2, co return SELABEL_INCOMPARABLE; } -static enum selabel_cmp_result cmp(struct selabel_handle *h1, - struct selabel_handle *h2) +static enum selabel_cmp_result cmp(const struct selabel_handle *h1, + const struct selabel_handle *h2) { - struct saved_data *data1 = (struct saved_data *)h1->data; - struct saved_data *data2 = (struct saved_data *)h2->data; + const struct saved_data *data1 = (const struct saved_data *)h1->data; + const struct saved_data *data2 = (const struct saved_data *)h2->data; unsigned int i, nspec1 = data1->nspec, j, nspec2 = data2->nspec; - struct spec *spec_arr1 = data1->spec_arr, *spec_arr2 = data2->spec_arr; - struct stem *stem_arr1 = data1->stem_arr, *stem_arr2 = data2->stem_arr; + const struct spec *spec_arr1 = data1->spec_arr, *spec_arr2 = data2->spec_arr; + const struct stem *stem_arr1 = data1->stem_arr, *stem_arr2 = data2->stem_arr; bool skipped1 = false, skipped2 = false; i = 0; j = 0; while (i < nspec1 && j < nspec2) { - struct spec *spec1 = &spec_arr1[i]; - struct spec *spec2 = &spec_arr2[j]; + const struct spec *spec1 = &spec_arr1[i]; + const struct spec *spec2 = &spec_arr2[j]; /* * Because sort_specs() moves exact pathnames to the @@ -1297,8 +1297,8 @@ static enum selabel_cmp_result cmp(struct selabel_handle *h1, if (spec2->stem_id == -1 && spec1->stem_id != -1) return incomp(spec1, spec2, "stem_id", i, j); if (spec1->stem_id != -1 && spec2->stem_id != -1) { - struct stem *stem1 = &stem_arr1[spec1->stem_id]; - struct stem *stem2 = &stem_arr2[spec2->stem_id]; + const struct stem *stem1 = &stem_arr1[spec1->stem_id]; + const struct stem *stem2 = &stem_arr2[spec2->stem_id]; if (stem1->len != stem2->len || strncmp(stem1->buf, stem2->buf, stem1->len)) return incomp(spec1, spec2, "stem", i, j); diff --git a/libselinux/src/label_internal.h b/libselinux/src/label_internal.h index 273a630a..bc5a6928 100644 --- a/libselinux/src/label_internal.h +++ b/libselinux/src/label_internal.h @@ -98,8 +98,8 @@ struct selabel_handle { const char *key, const char **aliases, int type); - enum selabel_cmp_result (*func_cmp)(struct selabel_handle *h1, - struct selabel_handle *h2); + enum selabel_cmp_result (*func_cmp)(const struct selabel_handle *h1, + const struct selabel_handle *h2); /* supports backend-specific state information */ void *data;
Comparing two selabel handles should (and currently does) not modify them. Signed-off-by: Christian Göttsche <cgzones@googlemail.com> --- libselinux/include/selinux/label.h | 4 ++-- libselinux/src/label.c | 4 ++-- libselinux/src/label_file.c | 22 +++++++++++----------- libselinux/src/label_internal.h | 4 ++-- 4 files changed, 17 insertions(+), 17 deletions(-)