diff -urN shadow-4.0.3.orig/lib/Makefile.am shadow-4.0.3/lib/Makefile.am --- shadow-4.0.3.orig/lib/Makefile.am 2001-10-06 14:53:20.000000000 -0500 +++ shadow-4.0.3/lib/Makefile.am 2003-08-07 08:38:20.000000000 -0500 @@ -1,7 +1,7 @@ AUTOMAKE_OPTIONS = 1.0 foreign -DEFS = +DEFS = -DWITH_SELINUX INCLUDES = -I$(top_srcdir) lib_LTLIBRARIES = libshadow.la diff -urN shadow-4.0.3.orig/lib/commonio.c shadow-4.0.3/lib/commonio.c --- shadow-4.0.3.orig/lib/commonio.c 2001-11-17 07:15:52.000000000 -0600 +++ shadow-4.0.3/lib/commonio.c 2003-08-07 08:38:20.000000000 -0500 @@ -15,7 +15,10 @@ #ifdef HAVE_SHADOW_H #include #endif - +#ifdef WITH_SELINUX +#include +static security_context_t old_context=NULL; +#endif #include "commonio.h" /* local function prototypes */ @@ -437,6 +440,15 @@ return 0; } +#ifdef WITH_SELINUX + db->scontext=NULL; + if (is_selinux_enabled() && (! db->readonly)) { + if (fgetfilecon(fileno(db->fp),&db->scontext) < 0) { + goto cleanup; + } + } +#endif + buflen = BUFLEN; buf = (char *) malloc(buflen); if (!buf) @@ -492,6 +504,12 @@ free(buf); cleanup: free_linked_list(db); +#ifdef WITH_SELINUX + if (db->scontext!= NULL) { + freecon(db->scontext); + db->scontext=NULL; + } +#endif fclose(db->fp); db->fp = NULL; errno = ENOMEM; @@ -627,6 +645,19 @@ goto fail; } +#ifdef WITH_SELINUX + if (db->scontext != NULL) { + int stat=getfscreatecon(&old_context); + if (stat< 0) { + errors++; + goto fail; + } + if (setfscreatecon(db->scontext)<0) { + errors++; + goto fail; + } + } +#endif /* * Create backup file. */ @@ -683,14 +714,26 @@ goto fail; nscd_need_reload = 1; - + goto success; +fail: + errors++; success: - free_linked_list(db); - return 1; -fail: +#ifdef WITH_SELINUX + if (db->scontext != NULL) { + if (setfscreatecon(old_context)<0) { + errors++; + } + if (old_context != NULL) { + freecon(old_context); + old_context=NULL; + } + freecon(db->scontext); + db->scontext=NULL; + } +#endif free_linked_list(db); - return 0; + return errors==0; } diff -urN shadow-4.0.3.orig/lib/commonio.h shadow-4.0.3/lib/commonio.h --- shadow-4.0.3.orig/lib/commonio.h 2001-08-14 16:09:54.000000000 -0500 +++ shadow-4.0.3/lib/commonio.h 2003-08-07 08:38:20.000000000 -0500 @@ -1,5 +1,8 @@ /* $Id: shadow-4.0.3-selinux.diff,v 1.1 2003/10/29 03:14:07 pebenito Exp $ */ +#ifdef WITH_SELINUX +#include +#endif /* * Linked list entry. */ @@ -70,6 +73,9 @@ */ FILE *fp; +#ifdef WITH_SELINUX + security_context_t scontext; +#endif /* * Head, tail, current position in linked list. */ diff -urN shadow-4.0.3.orig/src/Makefile.am shadow-4.0.3/src/Makefile.am --- shadow-4.0.3.orig/src/Makefile.am 2002-03-10 01:12:52.000000000 -0600 +++ shadow-4.0.3/src/Makefile.am 2003-08-07 08:38:20.000000000 -0500 @@ -4,7 +4,7 @@ ubindir = ${prefix}/bin usbindir = ${prefix}/sbin -DEFS = -D_HAVE_CONFIG_H -DLOCALEDIR=\"$(datadir)/locale\" +DEFS = -D_HAVE_CONFIG_H -DLOCALEDIR=\"$(datadir)/locale\" -DWITH_SELINUX INCLUDES = -I${top_srcdir} \ -I${top_srcdir}/lib \ @@ -35,7 +35,7 @@ suidubins = chage chfn chsh expiry gpasswd newgrp passwd LDADD = $(top_builddir)/libmisc/libmisc.la \ - $(top_builddir)/lib/libshadow.la + $(top_builddir)/lib/libshadow.la -lselinux chpasswd_LDADD = $(LDADD) $(LIBPAM) chage_LDADD = $(LDADD) $(LIBPAM) diff -urN shadow-4.0.3.orig/src/Makefile.in shadow-4.0.3/src/Makefile.in --- shadow-4.0.3.orig/src/Makefile.in 2002-03-13 13:04:10.000000000 -0600 +++ shadow-4.0.3/src/Makefile.in 2003-08-07 08:45:13.000000000 -0500 @@ -145,7 +145,7 @@ suidubins = chage chfn chsh expiry gpasswd newgrp passwd LDADD = $(top_builddir)/libmisc/libmisc.la \ - $(top_builddir)/lib/libshadow.la + $(top_builddir)/lib/libshadow.la -lselinux chpasswd_LDADD = $(LDADD) $(LIBPAM)