All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ivan Gyurdiev <ivg2@cornell.edu>
To: SELinux List <SELinux@tycho.nsa.gov>
Cc: Stephen Smalley <sds@tycho.nsa.gov>
Subject: [ SEPOL 3 ] Improve/fix sepol_user_set_roles
Date: Mon, 31 Oct 2005 06:04:33 -0500	[thread overview]
Message-ID: <4365FA41.8010302@cornell.edu> (raw)

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

- fix set_roles to properly handle num_roles = 0
- simplify a bit...



[-- Attachment #2: libsepol.set_roles.diff --]
[-- Type: text/x-patch, Size: 1950 bytes --]

diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION --exclude Makefile old/libsepol/src/user_record.c new/libsepol/src/user_record.c
--- old/libsepol/src/user_record.c	2005-10-31 05:49:40.000000000 -0500
+++ new/libsepol/src/user_record.c	2005-10-31 06:01:54.000000000 -0500
@@ -209,37 +209,41 @@ int sepol_user_set_roles(
 	size_t num_roles) {
 
 	size_t i;
+	char** tmp_roles = NULL;
+	char* tmp_def_role = NULL;
 
-	/* First, make a copy */
-	char** tmp_roles = (char**) calloc(1, sizeof(char*) * num_roles);
-	if (!tmp_roles) 
-		goto omem;
+	if (num_roles > 0) {
 
-	for (i = 0; i < num_roles; i++) {
-		tmp_roles[i] = strdup(roles_arr[i]); 
-		if (!tmp_roles[i])
-			goto omem;	
-	}
+		/* First, make a copy */
+		tmp_roles = (char**) calloc(1, sizeof(char*) * num_roles);
+		if (!tmp_roles) 
+			goto omem;
 
-	/* Try to set defrole - there should be no failures following
-	 * this call, since the old def role is not saved */
-	if (sepol_user_set_defrole(handle, user, tmp_roles[0]) < 0)
-		goto err;
+		for (i = 0; i < num_roles; i++) {
+			tmp_roles[i] = strdup(roles_arr[i]); 
+			if (!tmp_roles[i])
+				goto omem;	
+		}
 
+		tmp_def_role = strdup(tmp_roles[0]);
+		if (!tmp_def_role) 
+			goto omem;
+	}
+	
 	/* Apply other changes */
 	for (i = 0; i < user->num_roles; i++)
 		free(user->roles[i]);
 	free(user->roles);
+	free(user->def_role);
 	user->roles = tmp_roles;
 	user->num_roles = num_roles;
+	user->def_role = tmp_def_role;
+
 	return STATUS_SUCCESS;
 
 	omem:
-	ERR(handle, "out of memory");
-
-	err:
-	ERR(handle, "could not "
-		"allocate roles array for user %s", user->name);
+	ERR(handle, "out of memory, could not allocate roles array for"
+		"user %s", user->name);
 
 	if (tmp_roles) {
 		for (i = 0; i < num_roles; i++ ) {
@@ -247,8 +251,9 @@ int sepol_user_set_roles(
 				break;
 			free(tmp_roles[i]);
 		}
-		free(tmp_roles);
 	}
+	free(tmp_roles);
+	free(tmp_def_role);
 	return STATUS_ERR;	
 }
 

             reply	other threads:[~2005-10-31 11:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-10-31 11:04 Ivan Gyurdiev [this message]
2005-10-31 16:11 ` [ SEPOL 3 ] Improve/fix sepol_user_set_roles 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=4365FA41.8010302@cornell.edu \
    --to=ivg2@cornell.edu \
    --cc=SELinux@tycho.nsa.gov \
    --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.