All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joshua Brindle <jbrindle@tresys.com>
To: selinux@tycho.nsa.gov
Subject: Red Hat's passwd
Date: Fri, 05 Aug 2005 12:14:07 -0400	[thread overview]
Message-ID: <42F3904F.5080401@tresys.com> (raw)

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

The attached patch removes the selinux code from Red Hat's passwd.c and 
uses the libselinux function checkPasswdAccess. Aside from eliminating 
some duplication this will make it easier for passwd to use the 
userspace security server with dynamic object classes since it will only 
require a libselinux change and both shadows passwd and Red Hats passwd 
will benefit.

Let me know if there are problems merging this into mainline.

Joshua

[-- Attachment #2: passwd-0.70-checkaccess.patch --]
[-- Type: text/plain, Size: 4363 bytes --]

diff -purN passwd-0.70/passwd.c passwd-0.70-new/passwd.c
--- passwd-0.70/passwd.c	2005-06-17 05:53:50.000000000 -0400
+++ passwd-0.70-new/passwd.c	2005-08-05 11:03:11.213620856 -0400
@@ -54,7 +54,6 @@
 #include <selinux/selinux.h>
 #include <selinux/context.h>
 #include <selinux/av_permissions.h>
-#include "selinux_utils.h"
 #endif
 
 #ifdef WITH_AUDIT
@@ -366,7 +365,8 @@ main(int argc, const char **argv)
 #ifdef WITH_SELINUX
 	if ((is_selinux_enabled() > 0) &&
 	    (getuid() == 0) &&
-	    (check_selinux_access(username, pwd->pw_uid, PASSWD__PASSWD) != 0)) {
+	    (pwd->pw_uid != getuid ()) &&
+	    (checkPasswdAccess(PASSWD__PASSWD) != 0)) {
 		security_context_t user_context;
 		if (getprevcon(&user_context) < 0) {
 			user_context = strdup(_("Unknown user context"));
diff -purN passwd-0.70/selinux_utils.c passwd-0.70-new/selinux_utils.c
--- passwd-0.70/selinux_utils.c	2005-01-25 17:00:49.000000000 -0500
+++ passwd-0.70-new/selinux_utils.c	1969-12-31 19:00:00.000000000 -0500
@@ -1,82 +0,0 @@
-/*
- * Copyright Red Hat, Inc., 2003,2004.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, and the entire permission notice in its entirety,
- *    including the disclaimer of warranties.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote
- *    products derived from this software without specific prior
- *    written permission.
- *
- * ALTERNATIVELY, this product may be distributed under the terms of
- * the GNU Public License, in which case the provisions of the GPL are
- * required INSTEAD OF the above restrictions.  (This clause is
- * necessary due to a potential bad interaction between the GPL and
- * the restrictions contained in a BSD-style copyright.)
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
- * OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/* Written by Daniel Walsh <dwalsh@redhat.com> */
-
-#include "config.h"
-#include <sys/types.h>
-#include <stdio.h>
-#include <string.h>
-#include <selinux/selinux.h>
-#include <selinux/flask.h>
-#include <selinux/av_permissions.h>
-#include <selinux/context.h>
-#include "selinux_utils.h"
-
-int
-check_selinux_access(const char *change_user, int change_uid, unsigned int access)
-{
-	int status = -1;
-	security_context_t user_context;
-	const char *user;
-
-	if (security_getenforce() == 0) {
-		status = 0;
-	} else {
-		if (getprevcon(&user_context) == 0) {
-			context_t c;
-			c = context_new(user_context);
-			user = context_user_get(c);
-			if (change_uid != 0 && strcmp(change_user, user) == 0) {
-				status = 0;
-			} else {
-				struct av_decision avd;
-				int retval;
-				retval = security_compute_av(user_context,
-							     user_context,
-							     SECCLASS_PASSWD,
-							     access,
-							     &avd);
-				if ((retval == 0) && 
-				    ((access & avd.allowed) == access)) {
-					status = 0;
-				}
-			}
-			context_free(c);
-			freecon(user_context);
-		}
-	}
-	return status;
-}
diff -purN passwd-0.70/selinux_utils.h passwd-0.70-new/selinux_utils.h
--- passwd-0.70/selinux_utils.h	2005-01-25 17:00:49.000000000 -0500
+++ passwd-0.70-new/selinux_utils.h	1969-12-31 19:00:00.000000000 -0500
@@ -1,4 +0,0 @@
-#ifndef __RH_SELINUX_UTILS_H
-#define __RH_SELINUX_UTILS_H
-int check_selinux_access(const char *change_user, int change_uid, unsigned int access);
-#endif

             reply	other threads:[~2005-08-05 16:20 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-08-05 16:14 Joshua Brindle [this message]
2005-08-05 17:12 ` Red Hat's passwd Colin Walters
2005-08-05 18:16   ` Joshua Brindle
2005-08-05 18:38     ` Colin Walters
2005-08-05 18:38     ` Daniel J Walsh
2005-08-05 19:07       ` Joshua Brindle
2005-08-05 19:21         ` Colin Walters
2005-08-05 19:26           ` Joshua Brindle
2005-08-11 15:00         ` Stephen Smalley
2005-08-11 15:52           ` Joshua Brindle
2005-08-13 10:23             ` Daniel J Walsh

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=42F3904F.5080401@tresys.com \
    --to=jbrindle@tresys.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.