From: Daniel J Walsh <dwalsh@redhat.com>
To: Stephen Smalley <sds@tycho.nsa.gov>
Cc: Darrel Goeddel <dgoeddel@TrustedCS.com>,
Ivan Gyurdiev <ivg2@cornell.edu>,
Karl MacMillan <kmacmillan@tresys.com>,
SELinux <SELinux@tycho.nsa.gov>
Subject: Re: getseuserbyname patch
Date: Thu, 29 Sep 2005 09:24:40 -0400 [thread overview]
Message-ID: <433BEB18.7000703@redhat.com> (raw)
In-Reply-To: <1127925593.25945.130.camel@moss-spartans.epoch.ncsc.mil>
[-- Attachment #1: Type: text/plain, Size: 195 bytes --]
Updated patch for libselinux.
I have a couple of questions?
Is s0:c1-s0:c2 a valid range? Is s0:c1-s0:c1,c2 implied or required?
Can this range read/write s0 files in MCS? MLS?
Dan
--
[-- Attachment #2: libselinux-rhat.patch --]
[-- Type: text/x-patch, Size: 6013 bytes --]
diff --exclude-from=exclude -N -u -r nsalibselinux/include/selinux/selinux.h libselinux-1.27.1/include/selinux/selinux.h
--- nsalibselinux/include/selinux/selinux.h 2005-09-01 11:17:40.000000000 -0400
+++ libselinux-1.27.1/include/selinux/selinux.h 2005-09-28 14:37:04.000000000 -0400
@@ -354,6 +354,25 @@
extern int selinux_raw_to_trans_context(security_context_t raw,
security_context_t *transp);
+
+/* the following functions are used to retrieve the SELinux user and their
+ security level via the Linux usernames selinux */
+
+#define SEUSERFILE "/etc/selinux/seusers.conf"
+
+/* Define data structures */
+typedef struct seuser {
+ char* username;
+ char* seusername;
+ char* level;
+} seuser_t;
+
+/* read /etc/selinux/seusers.conf file an return selinux user info */
+
+extern void freeseuser(seuser_t *seuser);
+
+extern int getseuserbyname(const char *name, seuser_t **r_seuser);
+
#ifdef __cplusplus
}
#endif
diff --exclude-from=exclude -N -u -r nsalibselinux/include/selinux/seuser.h libselinux-1.27.1/include/selinux/seuser.h
--- nsalibselinux/include/selinux/seuser.h 1969-12-31 19:00:00.000000000 -0500
+++ libselinux-1.27.1/include/selinux/seuser.h 2005-09-28 14:32:11.000000000 -0400
@@ -0,0 +1,32 @@
+#ifndef _SEUSER_H_
+#define _SEUSER_H_
+
+#include <sys/types.h>
+#include <stdarg.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#define SEUSERFILE "/etc/selinux/seusers.conf"
+
+/* Define data structures */
+typedef struct seuser {
+ char* username;
+ char* seusername;
+ char* sensitivity;
+ char* categories;
+} seuser_t;
+
+/* read /etc/selinux/seusers.conf file an return selinux user info */
+
+extern void free_seuser(seuser_t *seuser);
+
+extern int getseuserbyname(const char *name, seuser_t **r_seuser);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --exclude-from=exclude -N -u -r nsalibselinux/man/Makefile libselinux-1.27.1/man/Makefile
--- nsalibselinux/man/Makefile 2004-10-20 16:31:36.000000000 -0400
+++ libselinux-1.27.1/man/Makefile 2005-09-28 14:32:16.000000000 -0400
@@ -8,3 +8,6 @@
install -m 644 man3/*.3 $(MAN3DIR)
install -m 644 man8/*.8 $(MAN8DIR)
+clean:
+ -rm -f *~ \#*
+ -rm -f man8/*~ man8/\#*
diff --exclude-from=exclude -N -u -r nsalibselinux/src/seusers.c libselinux-1.27.1/src/seusers.c
--- nsalibselinux/src/seusers.c 1969-12-31 19:00:00.000000000 -0500
+++ libselinux-1.27.1/src/seusers.c 2005-09-28 14:48:28.000000000 -0400
@@ -0,0 +1,132 @@
+#include <unistd.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <selinux/selinux.h>
+#include <selinux/context.h>
+#include "selinux_internal.h"
+
+void freeseuser(seuser_t *seuser) {
+ if (!seuser) return;
+ if (seuser->username)
+ free(seuser->username);
+ if (seuser->seusername)
+ free(seuser->seusername);
+ if (seuser->level)
+ free(seuser->level);
+ free(seuser);
+ return;
+}
+
+/* Process line from SEUSERSFILE.
+ Remove white space and set name do data before the "=" and sename to data
+ after it */
+static int process_seusers(const char *buffer, seuser_t **r_user) {
+ seuser_t *user=NULL;
+ char *ptr;
+ int rc=-1;
+ char *tok;
+ char *newbuf=strdup(buffer);
+ if (!newbuf) return -1;
+
+ user=calloc(1, sizeof(seuser_t));
+ if (!user) return -1;
+
+ tok=strtok_r(newbuf,":",&ptr);
+ if (!tok) goto err;
+ if ( tok[0]=='#' ) goto err;
+ user->username=strdup(tok);
+ if (!user->username) {
+ freeseuser(user);
+ rc=-1;
+ goto err;
+ }
+
+ tok=strtok_r(NULL,":",&ptr);
+ if (!tok) goto err;
+ while (isspace(*tok)) tok++;
+ if(strlen(tok))
+ user->seusername=strdup(tok);
+ if (!user->seusername) {
+ freeseuser(user);
+ rc=-1;
+ goto err;
+ }
+
+ tok=strtok_r(NULL,":",&ptr);
+ if (!tok) goto err;
+ while (isspace(*tok)) tok++;
+ if(strlen(tok))
+ user->level=strdup(tok);
+ if (!user->level) {
+ freeseuser(user);
+ rc=-1;
+ goto err;
+ }
+
+ tok=strtok_r(NULL,":",&ptr);
+ if (tok) {
+ int len;
+ while (isspace(*tok)) tok++;
+ len=strlen(tok);
+ if(len) {
+ char *ptr=realloc(user->level, strlen(user->level) + len + 2);
+ if (ptr==NULL) {
+ freeseuser(user);
+ rc=-1;
+ goto err;
+ }
+ user->level=ptr;
+ strcat(user->level,":");
+ strcat(user->level,tok);
+ }
+ }
+
+ *r_user=user;
+ rc=0;
+err:
+ free(newbuf);
+ return rc;
+}
+
+int getseuserbyname(const char *name, seuser_t **r_seuser) {
+ FILE *cfg=NULL;
+ size_t size=0;
+ char *buffer=NULL;
+
+ static seuser_t *seuser=NULL;
+ static seuser_t *defaultseuser=NULL;
+
+ cfg = fopen(SEUSERFILE,"r");
+ if (!cfg) return -1;
+
+ while (getline(&buffer, &size, cfg) > 0) {
+ if(process_seusers(buffer, &seuser) == 0) {
+ if (strcasecmp(seuser->username, name)==0)
+ break;
+
+ if (strcasecmp(seuser->username,"default")==0) {
+ if (defaultseuser) freeseuser(defaultseuser);
+ defaultseuser=seuser;
+ }
+ else
+ freeseuser(seuser);
+ seuser=NULL;
+ }
+ }
+ if (buffer) free(buffer);
+ fclose(cfg);
+ if (seuser) {
+ freeseuser(defaultseuser);
+ *r_seuser=seuser;
+ return 0;
+ }
+ if (defaultseuser) {
+ *r_seuser=defaultseuser;
+ return 0;
+ }
+
+ return -1;
+}
diff --exclude-from=exclude -N -u -r nsalibselinux/utils/getseuser.c libselinux-1.27.1/utils/getseuser.c
--- nsalibselinux/utils/getseuser.c 1969-12-31 19:00:00.000000000 -0500
+++ libselinux-1.27.1/utils/getseuser.c 2005-09-28 14:49:21.000000000 -0400
@@ -0,0 +1,27 @@
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <getopt.h>
+#include <errno.h>
+#include <string.h>
+#include <selinux/selinux.h>
+
+void usage(const char *progname)
+{
+ fprintf(stderr, "usage: %s\n", progname);
+ exit(1);
+}
+int main(int argc, char **argv) {
+ seuser_t *seuser;
+ if ( argc != 2 ) usage(argv[0]);
+ if (getseuserbyname(argv[1], &seuser) == 0 ) {
+ printf("%s\n", seuser->username);
+ printf("%s\n", seuser->seusername);
+ printf("%s", seuser->level);
+ freeseuser(seuser);
+ return 0;
+ } else {
+ printf("%s not found\n", argv[1]);
+ return -1;
+ }
+}
next prev parent reply other threads:[~2005-09-29 13:24 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-09-27 18:25 getseuserbyname patch Daniel J Walsh
2005-09-28 16:39 ` Stephen Smalley
2005-09-29 13:24 ` Daniel J Walsh [this message]
2005-09-29 13:35 ` Stephen Smalley
2005-09-29 15:10 ` Stephen Smalley
2005-09-29 15:23 ` Daniel J Walsh
2005-09-29 15:20 ` Stephen Smalley
2005-09-29 19:11 ` Daniel J Walsh
2005-09-29 21:21 ` Stephen Smalley
2005-10-03 15:52 ` Stephen Smalley
2005-10-03 16:29 ` Stephen Smalley
2005-10-06 13:16 ` Stephen Smalley
2005-10-06 13:27 ` Daniel J Walsh
2005-10-06 13:38 ` Stephen Smalley
2005-10-06 13:52 ` Daniel J Walsh
2005-10-06 16:52 ` Stephen Smalley
2005-10-06 17:10 ` Daniel J Walsh
2005-10-06 18:33 ` 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=433BEB18.7000703@redhat.com \
--to=dwalsh@redhat.com \
--cc=SELinux@tycho.nsa.gov \
--cc=dgoeddel@TrustedCS.com \
--cc=ivg2@cornell.edu \
--cc=kmacmillan@tresys.com \
--cc=sds@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.