From: "Joshua Brindle" <JBrindle@snu.edu>
To: <SELinux@tycho.nsa.gov>
Subject: [BETTER PATCH] support for altroot in setfiles
Date: Fri, 09 May 2003 16:30:11 -0500 [thread overview]
Message-ID: <sebbd79d.022@atlas.snu.edu> (raw)
[-- Attachment #1: Type: text/plain, Size: 562 bytes --]
Ok, i apoligize to everyone for posting that horribly insecure
patch on this list :) I was going for functionality so that i could
get it working then hope that someone else would fix it up,
and someone did, a fellow gentoo developer zach welch
(zwelch@gentoo.org) corrected all the buffer and memory problems
we could find so hopefully this will be much easier to audit and
incorporate into cvs. Thanks russel and steve for your replies,
hope you guys like this one better.
Joshua Brindle
UNIX Administrator
Southern Nazarene University
[-- Attachment #2: setfiles.c[1].patch --]
[-- Type: application/octet-stream, Size: 2402 bytes --]
--- setfiles-orig.c 2003-05-08 18:17:48.000000000 -0700
+++ setfiles.c 2003-05-09 14:19:40.000000000 -0700
@@ -89,6 +89,10 @@
static int use_inum = 0;
static int quiet = 0;
+
+static char *rootpath = NULL;
+static int rootpathlen = 0;
+
#define QPRINTF(args...) do { if (!quiet) printf(args); } while (0)
/*
@@ -283,15 +287,27 @@
int match(const char *name, struct stat *sb, security_id_t *out_sid)
{
int i, ret;
+ const char *fullname = name;
+
+ /* fullname will be the real file that gets labeled
+ * name will be what is matched in the policy */
+ if (NULL != rootpath) {
+ if (0 != strncmp(rootpath, name, rootpathlen)) {
+ fprintf(stderr, "%s: %s is not located in %s\n",
+ progname, name, rootpath);
+ return -1;
+ }
+ name += rootpathlen;
+ }
if (flask_enabled) {
- ret = lstat_secure(name, sb, out_sid);
+ ret = lstat_secure(fullname, sb, out_sid);
} else {
- ret = lstat(name, sb);
+ ret = lstat(fullname, sb);
}
if (ret) {
fprintf(stderr, "%s: unable to stat file %s\n", progname,
- name);
+ fullname);
return -1;
}
@@ -564,6 +580,23 @@
return 0;
}
+void set_rootpath(const char *arg)
+{
+ int len;
+
+ rootpath = strdup(arg);
+ if (NULL == rootpath) {
+ fprintf(stderr, "%s: insufficient memory for rootpath\n",
+ progname);
+ exit(1);
+ }
+
+ /* trim trailing /, if present */
+ len = strlen(rootpath);
+ while ('/' == rootpath[len - 1])
+ rootpath[--len] = 0;
+ rootpathlen = len;
+}
int main(int argc, char **argv)
{
@@ -577,7 +610,7 @@
struct stat sb;
/* Process any options. */
- while ((opt = getopt(argc, argv, "dinqsvRW")) > 0) {
+ while ((opt = getopt(argc, argv, "dinqsvrRW")) > 0) {
switch (opt) {
case 'd':
debug = 1;
@@ -604,6 +637,20 @@
case 'i':
use_inum = 1;
break;
+ case 'r':
+ if (optind + 1 >= argc) {
+ fprintf(stderr, "usage: %s -r rootpath\n",
+ argv[0]);
+ exit(1);
+ }
+ if (NULL != rootpath) {
+ fprintf(stderr,
+ "%s: only one -r can be specified\n",
+ argv[0]);
+ exit(1);
+ }
+ set_rootpath(argv[optind++]);
+ break;
}
}
@@ -919,7 +966,11 @@
}
else for (; optind < argc; optind++)
{
-
+ if (NULL != rootpath) {
+ QPRINTF("%s: labeling files, pretending %s is /\n",
+ argv[0], rootpath);
+ }
+
if (flask_enabled) {
QPRINTF("%s: labeling files under %s\n", argv[0],
argv[optind]);
reply other threads:[~2003-05-09 21:30 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=sebbd79d.022@atlas.snu.edu \
--to=jbrindle@snu.edu \
--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.