All of lore.kernel.org
 help / color / mirror / Atom feed
From: Maria Iano <maria@iano.org>
To: Stephen Smalley <sds@tycho.nsa.gov>
Cc: selinux@tycho.nsa.gov
Subject: Re: correct way to set context in perl?
Date: Fri, 19 May 2006 13:04:03 -0400	[thread overview]
Message-ID: <20060519130403.C26098@iano.org> (raw)
In-Reply-To: <1148053480.25168.150.camel@moss-spartans.epoch.ncsc.mil>; from sds@tycho.nsa.gov on Fri, May 19, 2006 at 11:44:40AM -0400

You're right - I'll move the context types into the config file. I'll use the -t option as you suggest as well. Thanks very much for your help.

I have a pair of .te and .fc files for my application, so next time it boots they will get labelled correctly anyway.

Generating perl bindings is probably way out of my league, but I will take a look at it.

Every time a zone is edited, the scripts append the diffs to a running log file of diffs for that zone. These files are kept in a directory called diffs and the name server never needs to read or write to them, so I gave it type etc_t because I don't know any better. So here is how it looks now:

my $namedpath;
if ($ARGV[0] =~ /--dir=([^)]+)/) {
    $namedpath = $1;
} else {
    $namedpath = $config->{fulldirectory};
}
my $master_type = $config->{master_type} || 'named_zone_t';
my $slave_type = $config->{slave_type} || 'named_cache_t';
my $diff_type = $config->{diff_type} || 'etc_t';
my $named_dir_type = $config->{named_dir_type} || $master_type;

unless ($namedpath) {
    die "The zone path was not found in the configuration file";
}
unless (-e $namedpath) {
    die "Could not create directory $namedpath" unless mkdir($namedpath,0770);
    system ('chcon','-t',$named_dir_type,"$namedpath");
}
unless (-e "$namedpath/slaves") {
    die "Could not create directory $namedpath/slaves"
                  unless mkdir("$namedpath/slaves",0770);
    system ('chcon','-t',$slave_type,"$namedpath/slaves");
}
unless (-e "$namedpath/diffs") {
    die "Could not create directory $namedpath/diffs"
                  unless mkdir("$namedpath/diffs",0770);
    system ('chcon','-t',$diff_type,"$namedpath/diffs");
}
my $masterpath = "$namedpath/master";
unless (-e $masterpath) {
    die "Could not create directory $masterpath" unless mkdir($masterpath,0770);
    system ('chcon','-t',$master_type,"$masterpath");
}

Thanks for your help,
Maria

On Fri, May 19, at 11:44%P so wrote Stephen Smalley (sds@tycho.nsa.gov):

> On Fri, 2006-05-19 at 11:33 -0400, Maria Iano wrote:
> > Even after reorganizing the directories I still see the need for setting context from a perl script. The first time the application runs the directories may not be there. So I've added this to one of the scripts, and it does seem to do what I need. I would appreciate any comments/advice on a better approach to this:
> > 
> > unless ($zonepath) {
> >     die "The zone path was not found in the configuration file";
> > }
> > unless (-e $zonepath) {
> >     die "Could not create directory $zonepath" unless mkdir($zonepath,0770);
> >     system ("chcon","system_u:object_r:named_zone_t","$zonepath");
> >     die "Could not create directory $zonepath/slaves"
> >                   unless mkdir("$zonepath/slaves",0770);
> >     system ("chcon","system_u:object_r:named_cache_t","$zonepath/slaves");
> > }
> > my $datapath = "$zonepath/master";
> > unless (-e $datapath) {
> >     die "Could not create directory $datapath" unless mkdir($datapath,0770);
> >     system ("chcon","system_u:object_r:named_zone_t","$datapath");
> > }
> 
> If using chcon, use the -t option so that you only need to specify the
> type (named_zone_t) and let the rest of the context be inferred.
> Ideally, you'd get even the type name from some config file.
> 
> python bindings have been added to libselinux via swig; generating perl
> bindings might be simple, particularly for simple functions like
> setfilecon(3).
> 
> -- 
> Stephen Smalley
> National Security Agency

--
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:[~2006-05-19 17:04 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-05-18 20:06 correct way to set context in perl? Maria Iano
2006-05-18 20:47 ` Erich Schubert
2006-05-18 21:12   ` Maria Iano
2006-05-18 22:47     ` Erich Schubert
2006-05-19 13:57     ` Russell Coker
2006-05-19 14:31       ` Maria Iano
2006-05-19 15:33         ` Maria Iano
2006-05-19 15:44           ` Stephen Smalley
2006-05-19 17:04             ` Maria Iano [this message]
2006-05-20 12:13         ` Russell Coker
2006-05-22 14:46           ` Maria Iano

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=20060519130403.C26098@iano.org \
    --to=maria@iano.org \
    --cc=sds@tycho.nsa.gov \
    --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.