Skip to content

Commit

Permalink
libselinux: ignore internal use of deprecated interfaces
Browse files Browse the repository at this point in the history
Ignore internal use of deprecated interfaces within deprecated
interfaces.

    compute_user.c: In function ‘security_compute_user’:
    compute_user.c:93:9: error: ‘security_compute_user_raw’ is deprecated: Use get_ordered_context_list(3) family [-Werror=deprecated-declarations]
       93 |         ret = security_compute_user_raw(rscon, user, con);
          |         ^~~
    compute_user.c:13:5: note: declared here
       13 | int security_compute_user_raw(const char * scon,
          |     ^~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Christian Göttsche <[email protected]>
  • Loading branch information
cgzones committed Nov 9, 2022
1 parent 262ed31 commit ae39165
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions libselinux/src/compute_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ int security_compute_user(const char * scon,
if (selinux_trans_to_raw_context(scon, &rscon))
return -1;

IGNORE_DEPRECATED_BEGIN
ret = security_compute_user_raw(rscon, user, con);
IGNORE_DEPRECATED_END

freecon(rscon);
if (!ret) {
Expand Down
11 changes: 11 additions & 0 deletions libselinux/src/matchpathcon.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,9 @@ int matchpathcon_init_prefix(const char *path, const char *subset)

int matchpathcon_init(const char *path)
{
IGNORE_DEPRECATED_BEGIN
return matchpathcon_init_prefix(path, NULL);
IGNORE_DEPRECATED_END
}

void matchpathcon_fini(void)
Expand Down Expand Up @@ -442,6 +444,8 @@ static int matchpathcon_internal(const char *path, mode_t mode, char ** con)
{
char stackpath[PATH_MAX + 1];
char *p = NULL;

IGNORE_DEPRECATED_BEGIN
if (!hnd && (matchpathcon_init_prefix(NULL, NULL) < 0))
return -1;

Expand All @@ -453,6 +457,7 @@ static int matchpathcon_internal(const char *path, mode_t mode, char ** con)
if (p)
path = p;
}
IGNORE_DEPRECATED_END

return notrans ?
selabel_lookup_raw(hnd, con, path, mode) :
Expand Down Expand Up @@ -510,8 +515,10 @@ int selinux_file_context_verify(const char *path, mode_t mode)
char *p = NULL;

if (S_ISLNK(mode)) {
IGNORE_DEPRECATED_BEGIN
if (!realpath_not_final(path, stackpath))
path = stackpath;
IGNORE_DEPRECATED_END
} else {
p = realpath(path, stackpath);
if (p)
Expand All @@ -526,8 +533,10 @@ int selinux_file_context_verify(const char *path, mode_t mode)
return 0;
}

IGNORE_DEPRECATED_BEGIN
if (!hnd && (matchpathcon_init_prefix(NULL, NULL) < 0))
return -1;
IGNORE_DEPRECATED_END

if (selabel_lookup_raw(hnd, &fcontext, path, mode) != 0) {
if (errno != ENOENT)
Expand Down Expand Up @@ -557,8 +566,10 @@ int selinux_lsetfilecon_default(const char *path)
if (lstat(path, &st) != 0)
return rc;

IGNORE_DEPRECATED_BEGIN
if (!hnd && (matchpathcon_init_prefix(NULL, NULL) < 0))
return -1;
IGNORE_DEPRECATED_END

/* If there's an error determining the context, or it has none,
return to allow default context */
Expand Down
14 changes: 14 additions & 0 deletions libselinux/src/selinux_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,20 @@ extern int selinux_page_size ;

extern int has_selinux_config ;

#ifdef __GNUC__
# define IGNORE_DEPRECATED_BEGIN \
_Pragma("GCC diagnostic push") \
_Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
#else
# define IGNORE_DEPRECATED_BEGIN
#endif

#ifdef __GNUC__
# define IGNORE_DEPRECATED_END _Pragma("GCC diagnostic pop")
#else
# define IGNORE_DEPRECATED_END
#endif

#ifndef HAVE_STRLCPY
size_t strlcpy(char *dest, const char *src, size_t size);
#endif
Expand Down

0 comments on commit ae39165

Please sign in to comment.