All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eamon Walsh <ewalsh@tycho.nsa.gov>
To: Karl MacMillan <kmacmillan@mentalrootkit.com>
Cc: SE Linux <selinux@tycho.nsa.gov>,
	Stephen Smalley <sds@tycho.nsa.gov>,
	Joshua Brindle <jbrindle@tresys.com>
Subject: Re: [PATCH 1/3] libselinux: labeling support (try 3)
Date: Mon, 11 Jun 2007 19:06:57 -0400	[thread overview]
Message-ID: <466DD591.4030004@tycho.nsa.gov> (raw)
In-Reply-To: <1181595322.6699.23.camel@localhost.localdomain>

Here's some test code that I've been using.  The program looks up
the command line argument as a file first, then as a media label.

The file options are set up with a "matchpathcon_prefix" of /etc and
validation turned on.

I can produce a patch for setfiles, but that will take a little
longer since all the inode code that was placed into libselinux has
to be put back into setfiles.


#include <stdio.h>
#include <stdlib.h>

#include <selinux/selinux.h>
#include <selinux/label.h>

static void test_file(const char *str)
{
	selabel_handle_t hnd;
	security_context_t result;
	int rc;
	struct selabel_opt opts[] = {
		{ SELABEL_OPT_PREFIX, "/etc" },
		{ SELABEL_OPT_VALIDATE, "1" }
	};

	hnd = selabel_open(SELABEL_CTX_FILE, opts, 2);
	if (!hnd) {
		perror("selabel_open");
		exit(1);
	}

	rc = selabel_lookup(hnd, &result, str, 0);
	if (rc < 0) {
		perror("selabel_lookup");
	} else {
		printf("File result is: %s\n", result);
		freecon(result);
	}
	
	selabel_close(hnd);
}

static void test_media(const char *str)
{
	selabel_handle_t hnd;
	security_context_t result;
	int rc;

	hnd = selabel_open(SELABEL_CTX_MEDIA, NULL, 0);
	if (!hnd) {
		perror("selabel_open");
		exit(1);
	}

	rc = selabel_lookup(hnd, &result, str, 0);
	if (rc < 0) {
		perror("selabel_lookup");
	} else {
		printf("Media result is: %s\n", result);
		freecon(result);
	}
	
	selabel_close(hnd);
}

int main(int argc, char **argv)
{
	if (argc != 2) {
		fprintf(stderr, "usage\n");
		return 1;
	}
		
	test_file(argv[1]);
	test_media(argv[1]);

	return 0;
}




-- 
Eamon Walsh <ewalsh@tycho.nsa.gov>
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:[~2007-06-11 23:06 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-11 19:27 [PATCH 1/3] libselinux: labeling support (try 3) Eamon Walsh
2007-06-11 19:37 ` [PATCH 2/3] " Eamon Walsh
2007-06-11 19:38 ` [PATCH 3/3] " Eamon Walsh
2007-06-14 12:19   ` Stephen Smalley
2007-06-11 20:55 ` [PATCH 1/3] " Karl MacMillan
2007-06-11 23:06   ` Eamon Walsh [this message]
2007-06-12 22:48     ` Eamon Walsh
2007-06-14 12:42       ` 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=466DD591.4030004@tycho.nsa.gov \
    --to=ewalsh@tycho.nsa.gov \
    --cc=jbrindle@tresys.com \
    --cc=kmacmillan@mentalrootkit.com \
    --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.