All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Smalley <sds@tycho.nsa.gov>
To: William Roberts <bill.c.roberts@gmail.com>
Cc: "selinux@tycho.nsa.gov" <selinux@tycho.nsa.gov>
Subject: Re: initial_sid context via libsepol
Date: Tue, 8 Mar 2016 08:42:30 -0500	[thread overview]
Message-ID: <56DED6C6.4000407@tycho.nsa.gov> (raw)
In-Reply-To: <CAFftDdrQaU2jaoTLEbExHL_Qyrqg3XFvpfs=cLsNnxC690yv9A@mail.gmail.com>

On 03/07/2016 08:32 PM, William Roberts wrote:
>
>
> On Mon, Mar 7, 2016 at 12:32 PM, Stephen Smalley <sds@tycho.nsa.gov
> <mailto:sds@tycho.nsa.gov>> wrote:
>
>     On 03/07/2016 01:44 PM, Stephen Smalley wrote:
>
>         On 03/07/2016 10:41 AM, Richard Haines wrote:
>
>
>
>
>
>
>                 On Saturday, 5 March 2016, 14:48, Richard Haines
>                 <richard_c_haines@btinternet.com
>                 <mailto:richard_c_haines@btinternet.com>> wrote:
>
>
>
>
>
>                 On Friday, 4 March 2016, 21:18, "Roberts, William C"
>                 <william.c.roberts@intel.com
>                 <mailto:william.c.roberts@intel.com>> wrote:
>
>
>
>
>
>
>                     How can one obtain the same value as
>                     /sys/fs/selinux/initial_contexts/file
>
>                 via libsepol?
>
>
>                     I’ve been digging around libsepol and its not quite
>                     clear to me.
>
>                     It looks as though the record is here:
>                                       context_struct_t *a = &((policydb_t
>
>                 *)pol.db)->ocontexts[OCON_ISID]->context[0];
>
>                                       context_struct_t *b = &((policydb_t
>
>                 *)pol.db)->ocontexts[OCON_ISID]->context[1];
>
>
>                                       printf("%u\n", a->type);
>                                       printf("%u\n",b->type);
>
>                     Prints:
>                     185
>                     0
>
>                     Not sure if this is right, and how to format the
>                     context struct to a
>                     string.
>
>                 I didn’t see any helpers.
>
>
>
>
>
>                 I've attached an example, hope it's useful
>
>
>             I've updated the example with more detail and display SID
>             name using
>             SID value not counter.
>
>
>         Any particular reason you didn't use sepol_sid_to_context()?
>
>
>     I guess context_to_string() on the context structure would work
>     better for your purposes.   sepol_sid_to_context() would require
>     loading the sidtab via policydb_load_isids() and setting the
>     internal policydb to the one you loaded via sepol_set_policydb().
>
>
>
> Seems as though its not exported api, but it does indeed print something:
> code:
> char *s;
> size_t len;
> context_struct_t *a = &((policydb_t
> *)pol.db)->ocontexts[OCON_ISID]->context[0];
>
> int rc = context_to_string(pol.handle, (policydb_t *)pol.db, a, &s, &len);
>
> printf("rc: %d\n", rc);
> printf("con: %s\n", s);
>
> prints:
>    rc: 0
>    con: u:object_r:null_device:s0
>
> However, I am after the initial sid for file, which this isn't it... is
> it in the ocontexts array under a different index?

ocontext[OCON_ISID] points to the head of a linked list of initial SIDs, 
with the values in ->sid[0] and the context structures in ->context[0]. 
  Richard's sample program showed you how to walk it and print out all 
the entries.  The symbolic names themselves aren't in the policydb, as 
he noted; you can grab it from the kernel source 
(linux/security/selinux/include/initial_sid_to_string.h) or from the 
refpolicy (run make in refpolicy/policy/flask and grab 
kernel/initial_sid_to_string.h).

  parent reply	other threads:[~2016-03-08 13:42 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-04 21:16 initial_sid context via libsepol Roberts, William C
2016-03-05 14:43 ` Richard Haines
2016-03-07 15:41   ` Richard Haines
2016-03-07 18:44     ` Stephen Smalley
2016-03-07 20:32       ` Stephen Smalley
2016-03-08  1:32         ` William Roberts
2016-03-08 13:12           ` Richard Haines
2016-03-08 13:35             ` Richard Haines
2016-03-08 13:49             ` Christopher J. PeBenito
2016-03-08 13:42           ` Stephen Smalley [this message]
2016-03-09  5:18             ` William Roberts
2016-03-09 14:09               ` Stephen Smalley
2016-03-09 15:37                 ` William Roberts
2016-03-09 17:12                   ` William Roberts
2016-03-09 15:42                 ` Stephen Smalley
2016-03-09 15:45                   ` William Roberts

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=56DED6C6.4000407@tycho.nsa.gov \
    --to=sds@tycho.nsa.gov \
    --cc=bill.c.roberts@gmail.com \
    --cc=selinux@tycho.nsa.gov \
    /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.