From 867e64881e4bbd4af854dc16265750a1933d7b34 Mon Sep 17 00:00:00 2001
From: Dan Walsh <dwalsh@redhat.com>
Date: Wed, 9 Oct 2013 17:54:02 -0400
Subject: [PATCH 40/74] genhomedircon is no longer a script, but a link to
 semodule

---
 policycoreutils/scripts/Makefile         | 11 -----------
 policycoreutils/scripts/genhomedircon.8  | 24 ------------------------
 policycoreutils/semodule/Makefile        |  9 +++++++--
 policycoreutils/semodule/genhomedircon.8 | 24 ++++++++++++++++++++++++
 policycoreutils/semodule/semodule.c      |  7 ++++++-
 5 files changed, 37 insertions(+), 38 deletions(-)
 delete mode 100644 policycoreutils/scripts/genhomedircon.8
 create mode 100644 policycoreutils/semodule/genhomedircon.8

diff --git a/policycoreutils/scripts/Makefile b/policycoreutils/scripts/Makefile
index 201a988..f5d6e9d 100644
--- a/policycoreutils/scripts/Makefile
+++ b/policycoreutils/scripts/Makefile
@@ -9,23 +9,12 @@ LOCALEDIR ?= $(PREFIX)/share/locale
 .PHONY: all genhomedircon
 all: fixfiles genhomedircon chcat
 
-genhomedircon:
-	@echo "#!/bin/sh" > genhomedircon
-	@echo >> genhomedircon
-	@if [ -z "${SEMODULE_PATH}" ]; then \
-		echo "${USRSBINDIR}/semodule -Bn" >> genhomedircon; \
-	else \
-		echo "${SEMODULE_PATH}/semodule -Bn" >> genhomedircon; \
-	fi
-
 install: all
 	-mkdir -p $(BINDIR)
 	install -m 755 chcat $(BINDIR)
 	install -m 755 fixfiles $(SBINDIR)
-	install -m 755 genhomedircon $(USRSBINDIR)
 	-mkdir -p $(MANDIR)/man8
 	install -m 644 fixfiles.8 $(MANDIR)/man8/
-	install -m 644 genhomedircon.8 $(MANDIR)/man8/
 	install -m 644 chcat.8 $(MANDIR)/man8/
 
 clean:
diff --git a/policycoreutils/scripts/genhomedircon.8 b/policycoreutils/scripts/genhomedircon.8
deleted file mode 100644
index 8ec509c..0000000
--- a/policycoreutils/scripts/genhomedircon.8
+++ /dev/null
@@ -1,24 +0,0 @@
-.TH GENHOMEDIRCON "12" "Sep 2011" "Security Enhanced Linux" "SELinux"
-.SH NAME
-genhomedircon \- generate SELinux file context configuration entries for user home directories
-.SH SYNOPSIS
-.B genhomedircon
-is a script that executes
-.B semodule
-to rebuild the currently active SELinux policy (without reloading it) and to create the
-labels for each user home directory based on directory paths returned by calls to getpwent().
-
-The latter functionality depends on the "usepasswd" parameter being set to "true" (default)
-in /etc/selinux/semanage.conf.
-
-This script is usually executed by
-.B semanage
-although this default behavior can be optionally modified by setting to "true" the
-"disable-genhomedircon" in /etc/selinux/semanage.conf.
-
-.SH AUTHOR
-This manual page was written by
-.I Dan Walsh <dwalsh@redhat.com>
-
-.SH "SEE ALSO"
-semanage.conf(5), semodule(8), semanage(8), getpwent(3), getpwent_r(3)
diff --git a/policycoreutils/semodule/Makefile b/policycoreutils/semodule/Makefile
index 4c5243a..161993e 100644
--- a/policycoreutils/semodule/Makefile
+++ b/policycoreutils/semodule/Makefile
@@ -11,7 +11,7 @@ LDLIBS = -lsepol -lselinux -lsemanage -L$(LIBDIR)
 SEMODULE_OBJS = semodule.o
 
 .PHONY: all semodule_path
-all: semodule semodule_path
+all: semodule semodule_path genhomedircon
 
 semodule_path:
 	@echo -n $(SBINDIR) > ../scripts/semodule_path
@@ -19,16 +19,21 @@ semodule_path:
 semodule: $(SEMODULE_OBJS)
 	$(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS)
 
+genhomedircon:
+	ln -sf semodule genhomedircon
+
 install: all
 	-mkdir -p $(SBINDIR)
 	install -m 755 semodule $(SBINDIR)
+	(cd $(SBINDIR); ln -sf semodule genhomedircon)
 	test -d $(MANDIR)/man8 || install -m 755 -d $(MANDIR)/man8
 	install -m 644 semodule.8 $(MANDIR)/man8/
+	install -m 644 genhomedircon.8 $(MANDIR)/man8/
 
 relabel:
 
 clean:
-	-rm -f semodule *.o ../scripts/semodule_path
+	-rm -f semodule *.o ../scripts/semodule_path genhomedircon
 
 indent:
 	../../scripts/Lindent $(wildcard *.[ch])
diff --git a/policycoreutils/semodule/genhomedircon.8 b/policycoreutils/semodule/genhomedircon.8
new file mode 100644
index 0000000..2a3315b
--- /dev/null
+++ b/policycoreutils/semodule/genhomedircon.8
@@ -0,0 +1,24 @@
+.TH GENHOMEDIRCON "8" "Sep 2011" "Security Enhanced Linux" "SELinux"
+.SH NAME
+genhomedircon \- generate SELinux file context configuration entries for user home directories
+.SH DESCRIPTION
+.B genhomedircon
+is a script that executes
+.B semodule
+to rebuild the currently active SELinux policy (without reloading it) and to create the
+labels for each user home directory based on directory paths returned by calls to getpwent().
+
+The latter functionality depends on the "usepasswd" parameter being set to "true" (default)
+in /etc/selinux/semanage.conf.
+
+This script is usually executed by
+.B semanage
+although this default behavior can be optionally modified by setting to "true" the
+"disable-genhomedircon" in /etc/selinux/semanage.conf.
+
+.SH AUTHOR
+This manual page was written by
+.I Dan Walsh <dwalsh@redhat.com>
+
+.SH "SEE ALSO"
+semanage.conf(5), semodule(8), semanage(8), getpwent(3), getpwent_r(3)
diff --git a/policycoreutils/semodule/semodule.c b/policycoreutils/semodule/semodule.c
index 17b4fa5..6947b37 100644
--- a/policycoreutils/semodule/semodule.c
+++ b/policycoreutils/semodule/semodule.c
@@ -19,6 +19,7 @@
 #include <sys/mman.h>
 #include <sys/stat.h>
 #include <sys/types.h>
+#include <libgen.h>
 
 #include <semanage/modules.h>
 
@@ -284,8 +285,12 @@ int main(int argc, char *argv[])
 	int i, commit = 0;
 	int result;
 	int status = EXIT_FAILURE;
-
+	char *genhomedirconargv[] = { "genhomedircon", "-B", "-n" };
 	create_signal_handlers();
+	if (strcmp(basename(argv[0]), "genhomedircon") == 0) {
+		argc = 3;
+		argv=genhomedirconargv;
+	} 
 	parse_command_line(argc, argv);
 
 	if (build)
-- 
1.8.3.1

