All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Todd C. Miller" <tmiller@tresys.com>
To: sds@tycho.nsa.gov, dwalsh@redhat.com
Cc: selinux@tycho.nsa.gov, jbrindle@tresys.com, tmiller@tresys.com
Subject: [patch 2/4] libsemanage: fix getpw*_r usage
Date: Thu, 27 Sep 2007 16:07:14 -0400	[thread overview]
Message-ID: <20070927200752.528616244@tresys.com> (raw)
In-Reply-To: 20070927200712.950671948@tresys.com

getpwnam_r() returns 0 when a user doesn't exist and just zeroes the
struct passwd pointer.  However, getpwent_r() returns ENOENT when there
are no more users.  This diff deals with both possible behaviors so that
if the two functions are brought in line nothing will break.  We can
also remove the errno check and use the return value directly.

Index: trunk/libsemanage/src/genhomedircon.c
===================================================================
--- trunk.orig/libsemanage/src/genhomedircon.c
+++ trunk/libsemanage/src/genhomedircon.c
@@ -158,6 +158,7 @@ static semanage_list_t *get_home_dirs(ge
 	size_t temp;
 	struct passwd pwstorage, *pwbuf;
 	struct stat buf;
+	int retval;
 
 	shells = get_shell_list();
 	assert(shells);
@@ -229,7 +230,7 @@ static semanage_list_t *get_home_dirs(ge
 	if (rbuf == NULL)
 		goto fail;
 	setpwent();
-	for (errno = 0; getpwent_r(&pwstorage, rbuf, rbuflen, &pwbuf) == 0; errno = 0) {
+	while ((retval = getpwent_r(&pwstorage, rbuf, rbuflen, &pwbuf)) == 0) {
 		if (pwbuf->pw_uid < minuid)
 			continue;
 		if (!semanage_list_find(shells, pwbuf->pw_shell))
@@ -252,7 +253,7 @@ static semanage_list_t *get_home_dirs(ge
 		free(path);
 	}
 
-	if (errno) {
+	if (retval && retval != ENOENT) {
 		WARN(s->h_semanage, "Error while fetching users.  "
 		     "Returning list so far.");
 	}
@@ -614,12 +615,13 @@ static genhomedircon_user_entry_t *get_u
 			prefix = name;
 		}
 
-		errno = 0;
-		if (getpwnam_r(name, &pwstorage, rbuf, rbuflen, &pwent) != 0) {
-			if (errno != 0) {
+		retval = getpwnam_r(name, &pwstorage, rbuf, rbuflen, &pwent);
+		if (retval != 0 || pwent == NULL) {
+			if (retval != 0 && retval != ENOENT) {
 				*errors = STATUS_ERR;
 				goto cleanup;
 			}
+
 			WARN(s->h_semanage,
 			     "user %s not in password file", name);
 			continue;

-- 


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to majordomo@tycho.nsa.gov with
the words "unsubscribe selinux" without quotes as the message.

  parent reply	other threads:[~2007-09-27 20:07 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-27 20:07 [patch 0/4] libsemanage: genhomedircon regressions Todd C. Miller
2007-09-27 20:07 ` [patch 1/4] libsemanage: validate homedir contexts Todd C. Miller
2007-09-27 20:07 ` Todd C. Miller [this message]
2007-09-27 20:07 ` [patch 3/4] libsemanage: update default user Todd C. Miller
2007-09-27 20:07 ` [patch 4/4] libsemanage: rebuild_file_context option Todd C. Miller
2007-09-28 13:36 ` [patch 0/4] libsemanage: genhomedircon regressions Stephen Smalley
2007-09-28 13:44   ` Stephen Smalley
2007-09-28 13:58     ` Daniel J Walsh
2007-09-28 13:51       ` Stephen Smalley
2007-09-28 13:55         ` Stephen Smalley
2007-09-28 15:06           ` Daniel J Walsh
2007-09-28 14:23     ` Todd Miller
2007-09-28 15:00       ` Todd Miller
2007-09-28 14:59         ` Stephen Smalley
2007-09-28 15:35           ` Joshua Brindle
2007-09-28 16:49             ` Stephen Smalley
2007-09-28 15:15       ` 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=20070927200752.528616244@tresys.com \
    --to=tmiller@tresys.com \
    --cc=dwalsh@redhat.com \
    --cc=jbrindle@tresys.com \
    --cc=sds@tycho.nsa.gov \
    --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.