All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel J Walsh <dwalsh@redhat.com>
To: ivg2@cornell.edu
Cc: SELinux@tycho.nsa.gov
Subject: Re: file_type_auto_trans is not sufficient
Date: Sun, 29 May 2005 06:52:33 -0400	[thread overview]
Message-ID: <42999EF1.3020205@redhat.com> (raw)
In-Reply-To: <1117336632.24194.8.camel@localhost.localdomain>

Ivan Gyurdiev wrote:

>>setfscreatecon takes precedence.
>>    
>>
>
>...on second thought this interface doesn't work at all - 
>apps call higher level functions for portability - the C
>standard functions (fopen...), glib (g_mkdir).
>
>Maybe just add:
>
>/* Performs a context match, and changes the file creation context.
> * On success, returns the old context. On failure, returns NULL.
> * The context returned must be freed with freecon() */
>
>security_context_t switch_context(const char* pathname, mode_t mode) {
>        security_context_t prev_ctx = NULL;
>        security_context_t tmp_ctx = NULL;
>
>        /* Attempt to get the current context. */
>        if (getfscreatecon(&prev_ctx) < 0)
>                return NULL;
>
>        /* Attempt a match. */
>        if (matchpathcon(pathname, mode, &tmp_ctx) >= 0) {
>                if (setfscreatecon(tmp_ctx) < 0) {
>                        freecon(tmp_ctx);
>                        freecon(prev_ctx);
>                        return NULL;
>                }
>                freecon(tmp_ctx);
>        }
>
>        return prev_ctx;
>}
>
>...and then do this in every app that needs it, replacing
>mkdir with the appropriate function. This is annoying.... 
>but I can't think how else to write a better interface.
>
>/* Performs a mkdir call, and sets the context of the directory
> * being created, according to matchpathcon. On SElinux failure
> * returns -1. Otherwise, returns the usual mkdir status. */
>
>int mkdir_restorecon(const char *pathname, mode_t mode) {
>        security_context_t prev_ctx = NULL;
>        int status;
>
>        if (is_selinux_enabled()) {
>                prev_ctx = switch_context(pathname, mode);
>
>                if ((prev_ctx != NULL) && security_getenforce())
>                        return -1;
>        }
>
>        status = mkdir(pathname, mode);
>
>        if (prev_ctx != NULL) {
>                setfscreatecon(prev_ctx);
>                freecon(prev_ctx);
>        }
>
>        return status;
>}
>
>  
>
You do not necessarily want to return an error or matchpathcon failure.  
matchpathcon can return ENOENT to indicate that it matched <<none>>

In this case the setfscreatecon should not be called but the code should 
continue.  IE the
file should get created with the default context.

-- 



--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to majordomo@tycho.nsa.gov with
the words "unsubscribe selinux" without quotes as the message.

  reply	other threads:[~2005-05-29 10:52 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-05-28  3:09 file_type_auto_trans is not sufficient Ivan Gyurdiev
2005-05-28  3:47 ` Ivan Gyurdiev
2005-05-28  5:24   ` Daniel J Walsh
2005-05-29  3:17     ` Ivan Gyurdiev
2005-05-29 10:52       ` Daniel J Walsh [this message]
2005-05-29 17:44         ` Ivan Gyurdiev
2005-05-30  3:03           ` Ivan Gyurdiev
2005-05-30  8:05             ` Ivan Gyurdiev
2005-05-31 13:36               ` Stephen Smalley
2005-05-31 15:09                 ` Ivan Gyurdiev
2005-05-31 13:18 ` Stephen Smalley
2005-05-31 13:35   ` Ivan Gyurdiev
2005-05-31 13:53     ` Stephen Smalley
2005-05-31 14:12     ` Karl MacMillan
2005-05-31 14:57       ` Ivan Gyurdiev
2005-05-31 16:32         ` Karl MacMillan
2005-05-31 16:48           ` Ivan Gyurdiev
2005-05-31 17:07             ` Stephen Smalley
2005-05-31 17:37               ` Ivan Gyurdiev
2005-05-31 17:39                 ` Stephen Smalley
2005-05-31 18:05                   ` Ivan Gyurdiev
2005-05-31 21:10                 ` Luke Kenneth Casson Leighton
2005-05-31 21:12             ` Luke Kenneth Casson Leighton
2005-05-31 21:21         ` Luke Kenneth Casson Leighton
2005-05-31 21:21           ` Luke Kenneth Casson Leighton
2005-05-31 23:09           ` Chad Sellers
2005-06-01  0:02             ` Luke Kenneth Casson Leighton
2005-06-01 11:21           ` Stephen Smalley
2005-06-01 11:21             ` Stephen Smalley

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=42999EF1.3020205@redhat.com \
    --to=dwalsh@redhat.com \
    --cc=SELinux@tycho.nsa.gov \
    --cc=ivg2@cornell.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.