All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel J Walsh <dwalsh@redhat.com>
To: SE Linux <selinux@tycho.nsa.gov>
Subject: This patch add seusers support to SELinux
Date: Mon, 18 May 2009 14:20:30 -0400	[thread overview]
Message-ID: <4A11A6EE.3070903@redhat.com> (raw)

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

The idea here is to break the seusers file up into lots of little 
seusers file that can be user specific, also adds the service field to 
be used by tools like pam_selinux to choose which is the correct context 
to log a user in as.

Patch was added to facilitate IPA handing out SELinux content for 
selection of roles at login.


[-- Attachment #2: libselinux_seusers.patch --]
[-- Type: text/plain, Size: 2444 bytes --]

--- nsalibselinux/include/selinux/selinux.h	2009-04-08 09:06:23.000000000 -0400
+++ libselinux-2.0.81/include/selinux/selinux.h	2009-05-18 14:04:07.000000000 -0400
@@ -544,6 +547,14 @@
    Caller must free the returned strings via free. */
 extern int getseuserbyname(const char *linuxuser, char **seuser, char **level);
 
+/* Get the SELinux username and level to use for a given Linux username and service. 
+   These values may then be passed into the get_ordered_context_list*
+   and get_default_context* functions to obtain a context for the user.
+   Returns 0 on success or -1 otherwise.
+   Caller must free the returned strings via free. */
+extern int getseuser(const char *username, const char *service, 
+		     char **r_seuser, char **r_level);
+
 /* Compare two file contexts, return 0 if equivalent. */
 int selinux_file_context_cmp(const security_context_t a,
 			     const security_context_t b);
--- nsalibselinux/src/seusers.c	2009-03-06 14:41:45.000000000 -0500
+++ libselinux-2.0.81/src/seusers.c	2009-05-18 14:04:07.000000000 -0400
@@ -243,3 +243,67 @@
 	*r_level = NULL;
 	return 0;
 }
+
+int getseuser(const char *username, const char *service, 
+	      char **r_seuser, char **r_level) {
+	int ret = -1;
+	int len = 0;
+	char *seuser = NULL;
+	char *level = NULL;
+	char *buffer = NULL;
+	size_t size = 0;
+	size_t lineno = 0;
+	char *rec = NULL;
+	char *path=NULL;
+	if (asprintf(&path,"%s/logins/%s", selinux_policy_root(), username) <  0)
+		goto err;
+	FILE *fp = fopen(path, "r");
+	free(path);
+	if (fp == NULL) goto err;
+	__fsetlocking(fp, FSETLOCKING_BYCALLER);
+	while (getline(&buffer, &size, fp) > 0) {
+		++lineno;
+
+		if (strncmp(buffer, "*:", 2) == 0) {
+			free(rec);
+			rec = strdup(buffer);
+			continue;
+		}
+		len = strlen(service);
+		if ((strncmp(buffer, service, len) == 0) &&
+		    (buffer[len] == ':')) {
+			free(rec);
+			rec = strdup(buffer);
+			break;
+		}
+	}
+
+	if (! rec)  goto err;
+	seuser = strchr(rec, ':');
+	if (! seuser) goto err;
+
+	seuser++;
+	level = strchr(seuser, ':');
+	*level = 0;
+	level++;
+	*r_seuser = strdup(seuser);
+	if (! *r_seuser) goto err;
+
+	len = strlen(level);
+	if (len && level[len-1] == '\n')
+		level[len-1] = 0;
+
+	*r_level = strdup(level);
+	if (! *r_level) {
+		free(*r_seuser);
+		goto err;
+	}
+	ret = 0;
+
+	err:
+	free(buffer);
+	if (fp) fclose(fp);
+	free(rec);
+
+	return (ret ? getseuserbyname(username, r_seuser, r_level) : ret);
+}

             reply	other threads:[~2009-05-18 18:20 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-18 18:20 Daniel J Walsh [this message]
2009-06-18 13:38 ` This patch add seusers support to SELinux Joshua Brindle
2009-06-18 13:48   ` Joshua Brindle
2009-06-18 19:37     ` Daniel J Walsh
2009-06-18 19:38     ` Daniel J Walsh
2009-06-18 20:14       ` Joshua Brindle
2009-06-19  9:57         ` Daniel J Walsh
2009-06-19 15:08           ` Joshua Brindle
2009-06-19 15:21             ` Daniel J Walsh
2009-06-19 18:13               ` Joshua Brindle
2009-06-19 18:24                 ` Daniel J Walsh
2009-06-19 18:27                   ` Joshua Brindle
2009-06-19 18:30                     ` Daniel J Walsh
2009-06-19 18:31                       ` Joshua Brindle
2009-06-19 18:39                         ` Daniel J Walsh
2009-06-19 18:29                 ` Daniel J Walsh
2009-06-19 19:30                   ` Chris PeBenito
2009-06-19 19:51                     ` Daniel J Walsh
2009-06-19 20:09                       ` Chris PeBenito
2009-06-22 15:10                         ` Joshua Brindle
2009-06-24 21:10                         ` Joshua Brindle
2009-06-25 12:31                           ` Stephen Smalley
2009-06-30 15:18               ` Joshua Brindle
2009-07-01 12:44                 ` Daniel J Walsh
2009-07-07 15:50                   ` Joshua Brindle
2009-07-07 16:05                     ` Joshua Brindle
2009-07-07 16:28                       ` Daniel J Walsh
2009-07-07 17:16                         ` Joshua Brindle
2009-07-07 17:27                           ` Daniel J Walsh
2009-07-08 14:05                             ` Joshua Brindle

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=4A11A6EE.3070903@redhat.com \
    --to=dwalsh@redhat.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.