All of lore.kernel.org
 help / color / mirror / Atom feed
From: KaiGai Kohei <kaigai@kaigai.gr.jp>
To: Denis Vlasenko <vda.linux@googlemail.com>
Cc: busybox@busybox.net, selinux@tycho.nsa.gov, russell@coker.com.au,
	rob@landley.net, busybox@kaigai.gr.jp
Subject: Re: [PATCH 7/8] busybox -- libselinux utilities applets
Date: Mon, 29 Jan 2007 22:43:43 +0900	[thread overview]
Message-ID: <45BDFA0F.7020706@kaigai.gr.jp> (raw)
In-Reply-To: <200701270050.27149.vda.linux@googlemail.com>

[-- Attachment #1: Type: text/plain, Size: 4380 bytes --]

Denis,

Thanks for your comments.

Denis Vlasenko wrote:
> On Thursday 25 January 2007 15:45, KaiGai Kohei wrote:
>> [7/8] busybox-libselinux-07-matchpathcon.patch
>>   matchpathcon - get the default security context for
>>   the specified path from the file contexts configuration.
>>   Security context is a identifier for SELinux.
>>   Any files has a own security context, and SELinux use it
>>   to evaluate the attribute of the file.
>>   When we are setting up a system, we have to attach a security
>>   context for each files. so, we can obtain the most appropriate
>>   security context by using matchpathcon.
>>
>> Signed-off-by: KaiGai Kohei <kaigai@kaigai.gr.jp>
>>
>> --
>> KaiGai Kohei <kaigai@kaigai.gr.jp>
> 
> 
> --- selinux/matchpathcon.c      (revision 0)
> +++ selinux/matchpathcon.c      (revision 0)
> @@ -0,0 +1,108 @@
> +/* matchpathcon  -  get the default security context for the specified
> + *                  path from the file contexts configuration.
> + *                  based on libselinux-1.32
> + * Port to busybox: KaiGai Kohei <kaigai@kaigai.gr.jp>
> + *
> + */
> +#include <unistd.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <getopt.h>
> +#include <errno.h>
> +#include <string.h>
> +#include <selinux/selinux.h>
> +#include "busybox.h"

I removed above redundant headers.

> +
> +static int printmatchpathcon(char *path, int header)
> +{
> +       char *buf;
> +       int rc = matchpathcon(path, 0, &buf);
> +       if (rc < 0) {
> +               fprintf(stderr, "matchpathcon(%s) failed: %s\n", path,
> +                       strerror(errno));
> +               return 1;
> +       }
> +       if (header)
> +               printf("%s\t%s\n", path, buf);
> +       else
> +               printf("%s\n", buf);
> +
> +       freecon(buf);
> +       return 0;
> +}
> +
> +#define MATCHPATHCON_OPT_NOT_PRINT     (1<<0)  /* -n */
> +#define MATCHPATHCON_OPT_NOT_TRANS     (1<<1)  /* -N */
> +#define MATCHPATHCON_OPT_FCONTEXT      (1<<2)  /* -f */
> +#define MATCHPATHCON_OPT_PREFIX                (1<<3)  /* -p */
> +#define MATCHPATHCON_OPT_VERIFY                (1<<4)  /* -V */
> +
> +int matchpathcon_main(int argc, char **argv)
> +{
> +       int i;
> +       int header = 1;
> +       int verify = 0;
> +       int notrans = 0;
> +       int error = 0;
> +       unsigned long opts;
> +       char *fcontext, *prefix;
> +
> +       if (argc < 2)
> +               bb_show_usage();
> +
> +       opts = getopt32(argc, argv, "nNf:p:V", &fcontext, &prefix);
> +       if (opts & BB_GETOPT_ERROR)
> +               bb_show_usage();
> +       if (opts & MATCHPATHCON_OPT_NOT_PRINT)
> +               header = 0;
> +       if (opts & MATCHPATHCON_OPT_NOT_TRANS) {
> +               notrans = 1;
> +               set_matchpathcon_flags(MATCHPATHCON_NOTRANS);
> +       }
> +       if ((opts & MATCHPATHCON_OPT_FCONTEXT) && (opts & MATCHPATHCON_OPT_PREFIX))
> +               bb_error_msg_and_die("-f and -p are exclusive");
> 
> This can be forced by just setting opt_complementary.
> There are a lot of examples in the tree.

The fixed patch uses opt_complementary and omit unnecessary as follows:
          :
     opt_complementary = "?:f--p:p--f";
     opts = getopt32(argc, argv, "nNf:p:V", &fcontext, &prefix);
          :

> +       if (opts & MATCHPATHCON_OPT_FCONTEXT) {
> +               if (matchpathcon_init(fcontext))
> +                       bb_error_msg_and_die("Error while processing %s: %s",
> 
> "<applet>: Error while...."  -- 'E' shpould be 'e' (small letter) here
> (and everywhere in bb_[ph]errorXXX)

OK, fixed.

- <snip> -

> Typically I avoid excessive indentation:
> 
>                if (!verify) {
>                        error += printmatchpathcon(argv[i], header);
>                        continue;
>                }
>                ...here entire old "if(verify)" block needs no indent now:
>                if (selinux_file_context_verify(argv[i], 0)) {
>                        printf("%s verified.\n", argv[i]);
>                } else {
>                ....

OK, I changed the code path as follows:

     if (!verify) {
         error += printmatchpathcon(argv[i], header);
         continue;
     }
     if (selinux_file_context_verify(argv[i], 0)) {
         printf("%s verified.\n", argv[i]);
         continue;
     }
         :

Thanks,
-- 
KaiGai Kohei <kaigai@kaigai.gr.jp>

[-- Attachment #2: busybox-libselinux-07-matchpathcon.v2.patch --]
[-- Type: text/x-patch, Size: 2732 bytes --]

Index: selinux/matchpathcon.c
===================================================================
--- selinux/matchpathcon.c	(revision 0)
+++ selinux/matchpathcon.c	(revision 0)
@@ -0,0 +1,98 @@
+/* matchpathcon  -  get the default security context for the specified
+ *                  path from the file contexts configuration.
+ *                  based on libselinux-1.32
+ * Port to busybox: KaiGai Kohei <kaigai@kaigai.gr.jp>
+ *
+ */
+#include "busybox.h"
+#include <selinux/selinux.h>
+
+static int printmatchpathcon(char *path, int header)
+{
+	char *buf;
+	int rc = matchpathcon(path, 0, &buf);
+	if (rc < 0) {
+		fprintf(stderr, "matchpathcon(%s) failed: %s\n",
+			path, strerror(errno));
+		return 1;
+	}
+	if (header)
+		printf("%s\t%s\n", path, buf);
+	else
+		printf("%s\n", buf);
+
+	freecon(buf);
+	return 0;
+}
+
+#define MATCHPATHCON_OPT_NOT_PRINT	(1<<0)	/* -n */
+#define MATCHPATHCON_OPT_NOT_TRANS	(1<<1)	/* -N */
+#define MATCHPATHCON_OPT_FCONTEXT	(1<<2)	/* -f */
+#define MATCHPATHCON_OPT_PREFIX		(1<<3)	/* -p */
+#define MATCHPATHCON_OPT_VERIFY		(1<<4)	/* -V */
+
+int matchpathcon_main(int argc, char **argv)
+{
+	int i;
+	int header = 1;
+	int verify = 0;
+	int notrans = 0;
+	int error = 0;
+	unsigned long opts;
+	char *fcontext, *prefix;
+
+	if (argc < 2)
+		bb_show_usage();
+
+	opt_complementary = "?:f--p:p--f";
+	opts = getopt32(argc, argv, "nNf:p:V", &fcontext, &prefix);
+	if (opts & MATCHPATHCON_OPT_NOT_PRINT)
+		header = 0;
+	if (opts & MATCHPATHCON_OPT_NOT_TRANS) {
+		notrans = 1;
+		set_matchpathcon_flags(MATCHPATHCON_NOTRANS);
+	}
+	if (opts & MATCHPATHCON_OPT_FCONTEXT) {
+		if (matchpathcon_init(fcontext))
+			bb_error_msg_and_die("error while processing %s: %s",
+					     fcontext, errno ? strerror(errno) : "invalid");
+	}
+	if (opts & MATCHPATHCON_OPT_PREFIX) {
+		if (matchpathcon_init_prefix(NULL, prefix))
+			bb_error_msg_and_die("error while processing %s:  %s",
+					     prefix, errno ? strerror(errno) : "invalid");
+	}
+	if (opts & MATCHPATHCON_OPT_VERIFY)
+		verify = 1;
+
+	for (i = optind; i < argc; i++) {
+		security_context_t con;
+		int rc;
+
+		if (!verify) {
+			error += printmatchpathcon(argv[i], header);
+			continue;
+		}
+
+		if (selinux_file_context_verify(argv[i], 0)) {
+			printf("%s verified.\n", argv[i]);
+			continue;
+		}
+
+		if (notrans)
+			rc = lgetfilecon_raw(argv[i], &con);
+		else
+			rc = lgetfilecon(argv[i], &con);
+
+		if (rc >= 0) {
+			printf("%s has context %s, should be ", argv[i], con);
+			error += printmatchpathcon(argv[i], 0);
+			freecon(con);
+		} else {
+			printf("actual context unknown: %s, should be ", strerror(errno));
+			error += printmatchpathcon(argv[i], 0);
+		}
+	}
+	matchpathcon_fini();
+	return error;
+}

  parent reply	other threads:[~2007-01-29 13:43 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-01-25 14:35 [PATCH 0/8] busybox -- libselinux utilities applets KaiGai Kohei
2007-01-25 14:44 ` [PATCH 2/8] " KaiGai Kohei
     [not found]   ` <200701270054.34561.vda.linux@googlemail.com>
2007-01-29 13:47     ` KaiGai Kohei
2007-01-25 14:44 ` [PATCH 3/8] " KaiGai Kohei
2007-01-25 14:44 ` [PATCH 4/8] " KaiGai Kohei
     [not found]   ` <200701270059.34996.vda.linux@googlemail.com>
2007-01-29 14:06     ` KaiGai Kohei
     [not found]       ` <20070130092817.GA32212@aon.at>
2007-01-31 12:13         ` [busybox:00323] " KaiGai Kohei
2007-01-25 14:44 ` [PATCH 5/8] " KaiGai Kohei
2007-01-26 20:10   ` Christopher J. PeBenito
2007-01-29 12:28     ` Russell Coker
2007-01-29 14:44       ` KaiGai Kohei
2007-01-25 14:44 ` [PATCH 6/8] " KaiGai Kohei
2007-01-25 14:45 ` [PATCH 7/8] " KaiGai Kohei
     [not found]   ` <200701270050.27149.vda.linux@googlemail.com>
2007-01-29 13:43     ` KaiGai Kohei [this message]
2007-01-25 14:45 ` [PATCH 8/8] " KaiGai Kohei
2007-01-26 15:29 ` [PATCH 0/8] " KaiGai Kohei
2007-01-29 17:38   ` James Carter
2007-01-26 19:36 ` Christopher J. PeBenito
2007-01-29 13:31   ` KaiGai Kohei

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=45BDFA0F.7020706@kaigai.gr.jp \
    --to=kaigai@kaigai.gr.jp \
    --cc=busybox@busybox.net \
    --cc=busybox@kaigai.gr.jp \
    --cc=rob@landley.net \
    --cc=russell@coker.com.au \
    --cc=selinux@tycho.nsa.gov \
    --cc=vda.linux@googlemail.com \
    /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.