All of lore.kernel.org
 help / color / mirror / Atom feed
* [patch 0/4] libsemanage: genhomedircon replacement
@ 2007-08-15 20:44 tmiller
  2007-08-15 15:10 ` Karl MacMillan
                   ` (4 more replies)
  0 siblings, 5 replies; 37+ messages in thread
From: tmiller @ 2007-08-15 20:44 UTC (permalink / raw)
  To: selinux

This replaces genhomedircon with equivalent functionality in libsemanage. The
homedir_template is also no longer installed, this leaves some unused path
functions in libselinux but removing those would break the ABI.

This does the same things that genhomedircon did though some seemed strange,
like removing /sbin/nologin from the list of valid shells, presumably to keep
ftp users and such from getting file contexts generated for them, I'm not sure
how valid the assumption is but we didn't want to change the functionality of
genhomedircon in this patch set.

This patch also generalizes some functionality of genhomedircon so that it can
be extended in the future (ex: for policy server user contexts)

The first patch does some cleanup to make way for the new genhomedircon.

The second patch adds genhomedircon.c and utilities.c to libsemanage. It calls
the code in genhomedircon.c from semanage_store.c and removes the prior call
to genhomedircon. This version uses libustr for string manipulations, which
creates an external dependency available in the development yum repository.
There is, however, an option to embed the ustr code directly into the library
and eliminate the runtime dependency.

The third patch is a set of tests for the new functions in utilities.c.

The final patch removes the old genhomedircon script.

Signed-Off-By: Todd Miller <tmiller@tresys.com>

-- 

--
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.

^ permalink raw reply	[flat|nested] 37+ messages in thread
* Re: [patch 0/4] libsemanage: genhomedircon replacement
@ 2007-09-06 19:16 Todd C. Miller
  0 siblings, 0 replies; 37+ messages in thread
From: Todd C. Miller @ 2007-09-06 19:16 UTC (permalink / raw)
  To: Stephen Smalley; +Cc: selinux

Stephen Smalley wrote:
> BTW, the C code shouldn't be using getpwnam or getpwent - it should be
> using the _r versions of those functions since it is a library.

Below is a diff to use the _r versions.  I sent this out some time ago
but apparently it didn't make it to the list.

 - todd

 genhomedircon.c |   32 +++++++++++++++++++++++++++-----
 1 file changed, 27 insertions(+), 5 deletions(-)

Index: libsemanage/src/genhomedircon.c
===================================================================
--- libsemanage/src/genhomedircon.c	(revision 2549)
+++ libsemanage/src/genhomedircon.c	(working copy)
@@ -41,6 +41,7 @@
 #include <fcntl.h>
 #include <pwd.h>
 #include <errno.h>
+#include <unistd.h>
 
 /* paths used in get_home_dirs() */
 #define PATH_ETC_USERADD "/etc/default/useradd"
@@ -145,11 +146,13 @@
 {
 	semanage_list_t *homedir_list = NULL;
 	semanage_list_t *shells = NULL;
+	char *rbuf = NULL;
 	char *path = NULL;
+	long rbuflen;
 	size_t minuid = 0;
 	size_t minuid_set = 0;
 	size_t temp;
-	struct passwd *pwbuf;
+	struct passwd pwstorage, *pwbuf;
 	struct stat buf;
 
 	shells = get_shell_list();
@@ -215,8 +218,14 @@
 		minuid_set = 1;
 	}
 
+	rbuflen = sysconf(_SC_GETPW_R_SIZE_MAX);
+	if (rbuflen <= 0)
+		goto fail;
+	rbuf = malloc(rbuflen);
+	if (rbuf == NULL)
+		goto fail;
 	setpwent();
-	for (errno = 0; (pwbuf = getpwent()); errno = 0) {
+	for (errno = 0; getpwent_r(&pwstorage, rbuf, rbuflen, &pwbuf) == 0; errno = 0) {
 		if (pwbuf->pw_uid < minuid)
 			continue;
 		if (!semanage_list_find(shells, pwbuf->pw_shell))
@@ -244,6 +253,7 @@
 		     "Returning list so far.");
 	}
 	endpwent();
+	free(rbuf);
 	semanage_list_destroy(&shells);
 	if (semanage_list_sort(&homedir_list))
 		goto fail;
@@ -251,6 +261,8 @@
 	return homedir_list;
 
       fail:
+	endpwent();
+	free(rbuf);
 	semanage_list_destroy(&homedir_list);
 	semanage_list_destroy(&shells);
 	return NULL;
@@ -496,8 +508,10 @@
 	const char *name = NULL;
 	const char *seuname = NULL;
 	const char *prefix = NULL;
-	struct passwd *pwent = NULL;
+	struct passwd pwstorage, *pwent = NULL;
 	unsigned int i;
+	long rbuflen;
+	char *rbuf = NULL;
 	int retval;
 
 	*errors = 0;
@@ -514,6 +528,14 @@
 	qsort(user_list, nusers, sizeof(semanage_user_t *),
 	      (int (*)(const void *, const void *))&user_sort_func);
 
+	/* Allocate space for the getpwnam_r buffer */
+	rbuflen = sysconf(_SC_GETPW_R_SIZE_MAX);
+	if (rbuflen <= 0)
+		goto cleanup;
+	rbuf = malloc(rbuflen);
+	if (rbuf == NULL)
+		goto cleanup;
+
 	for (i = 0; i < nseusers; i++) {
 		name = semanage_seuser_get_name(seuser_list[i]);
 		seuname = semanage_seuser_get_sename(seuser_list[i]);
@@ -536,8 +558,7 @@
 		}
 
 		errno = 0;
-		pwent = getpwnam(name);
-		if (!pwent) {
+		if (getpwnam_r(name, &pwstorage, rbuf, rbuflen, &pwent) != 0) {
 			if (errno != 0) {
 				*errors = STATUS_ERR;
 				goto cleanup;
@@ -561,6 +582,7 @@
 	}
 
       cleanup:
+	free(rbuf);
 	if (*errors) {
 		for (; head; pop_user_entry(&head)) {
 			/* the pop function takes care of all the cleanup

--
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.

^ permalink raw reply	[flat|nested] 37+ messages in thread

end of thread, other threads:[~2007-09-07 13:48 UTC | newest]

Thread overview: 37+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-15 20:44 [patch 0/4] libsemanage: genhomedircon replacement tmiller
2007-08-15 15:10 ` Karl MacMillan
2007-08-15 15:29   ` Joshua Brindle
2007-08-15 15:47     ` Karl MacMillan
2007-08-15 15:57       ` Joshua Brindle
2007-08-15 17:22         ` Stephen Smalley
2007-08-15 17:37           ` Joshua Brindle
2007-08-15 19:21             ` Karl MacMillan
2007-08-15 19:16           ` Karl MacMillan
2007-08-15 19:56             ` Stephen Smalley
2007-08-15 20:17               ` Karl MacMillan
2007-08-15 20:31                 ` Stephen Smalley
2007-08-15 20:41                   ` Karl MacMillan
2007-08-15 20:47                     ` Joshua Brindle
2007-08-15 21:09                       ` Karl MacMillan
2007-08-15 21:12                         ` Joshua Brindle
2007-08-15 21:40                           ` Joshua Brindle
2007-08-17 13:33                           ` Karl MacMillan
2007-08-16 16:01                         ` Stephen Smalley
2007-08-17 13:31                           ` Karl MacMillan
2007-08-17 18:20                             ` Joshua Brindle
2007-08-27 17:50                           ` Daniel J Walsh
2007-08-28 14:21                             ` Joshua Brindle
2007-08-28 14:30                               ` Stephen Smalley
2007-08-28 14:46                               ` Karl MacMillan
2007-08-28 16:37                                 ` Daniel J Walsh
2007-09-06 18:51                                   ` Stephen Smalley
2007-09-06 18:56                                     ` Karl MacMillan
2007-09-06 20:33                                       ` Daniel J Walsh
2007-09-07 13:48                                         ` Karl MacMillan
2007-08-15 20:44                   ` Joshua Brindle
2007-08-15 20:44 ` [patch 1/4] libsemanage: genhomedircon initial cleanup tmiller
2007-08-15 20:44 ` [patch 2/4] libsemanage: genhomedircon replacement tmiller
2007-08-16 19:31   ` Stephen Smalley
2007-08-15 20:44 ` [patch 3/4] libsemanage: test functions tmiller
2007-08-15 20:44 ` [patch 4/4] libsemanage: remove genhomedircon python script tmiller
  -- strict thread matches above, loose matches on Subject: below --
2007-09-06 19:16 [patch 0/4] libsemanage: genhomedircon replacement Todd C. Miller

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.