From efab223b05986c5fff7320004667c30b940fd743 Mon Sep 17 00:00:00 2001 From: nekral-guest Date: Tue, 18 Oct 2011 22:44:46 +0000 Subject: [PATCH] - debian/patches/401_cppw_src.dpatch, debian/patches/402_cppw_selinux: Synchronize with coding style. --- debian/changelog | 6 +- debian/patches/401_cppw_src.dpatch | 274 ++++++++++++++++------------- debian/patches/402_cppw_selinux | 70 ++++---- 3 files changed, 189 insertions(+), 161 deletions(-) diff --git a/debian/changelog b/debian/changelog index 6d7535b1..bdbdfdc6 100644 --- a/debian/changelog +++ b/debian/changelog @@ -45,11 +45,11 @@ shadow (1:4.1.5-1) unstable; urgency=low - debian/patches/008_su_get_PAM_username: Removed, feature supported upstream. - debian/patches/300_CVE-2011-0721: Removed, applied upstream. - - debian/patches/402_cppw_selinux: Avoid implicit conversion between - integer and boolean. - debian/patches/401_cppw_src.dpatch: Replace progname by Prog. Rename create_backup_file to create_copy. The lock functions do not ser errno. Do not report the error string on cppwexit. + - debian/patches/401_cppw_src.dpatch, debian/patches/402_cppw_selinux: + Synchronize with coding style. - Upstream translation updates from Debian BTS: + Brazilian Portuguese. Closes: #622834 + Catalan. Closes: #627526 @@ -79,7 +79,7 @@ shadow (1:4.1.5-1) unstable; urgency=low * Use "linux-any" instead of a negated list of architectures in Build-Depends. Closes: #634465 - -- Nicolas FRANCOIS (Nekral) Tue, 18 Oct 2011 22:43:04 +0200 + -- Nicolas FRANCOIS (Nekral) Wed, 19 Oct 2011 00:37:07 +0200 shadow (1:4.1.4.2+svn3283-3) unstable; urgency=high diff --git a/debian/patches/401_cppw_src.dpatch b/debian/patches/401_cppw_src.dpatch index 0816535c..49094de1 100755 --- a/debian/patches/401_cppw_src.dpatch +++ b/debian/patches/401_cppw_src.dpatch @@ -7,7 +7,7 @@ @DPATCH@ --- /dev/null +++ b/src/cppw.c -@@ -0,0 +1,201 @@ +@@ -0,0 +1,229 @@ +/* + cppw, cpgr copy with locking given file over the password or group file + with -s will copy with locking given file over shadow or gshadow file @@ -44,6 +44,7 @@ +#include +#include +#include ++#include "exitcodes.h" +#include "prototypes.h" +#include "pwio.h" +#include "shadowio.h" @@ -54,161 +55,188 @@ +const char *Prog; + +const char *filename, *filenewname; -+static int filelocked = 0; -+static int (*unlock)(); ++static bool filelocked = false; ++static int (*unlock) (void); + +/* local function prototypes */ -+static int create_copy (FILE *, const char *, struct stat *); -+static void cppwexit (const char *, int, int); -+static void cppwcopy (const char *, const char *, int (*) (void), int (*) (void)); -+int main (int, char **); ++static int create_copy (FILE *fp, const char *dest, struct stat *sb); ++static void cppwexit (const char *msg, int syserr, int ret); ++static void cppwcopy (const char *file, ++ const char *in_file, ++ int (*file_lock) (void), ++ int (*file_unlock) (void)); + -+static int -+create_copy (FILE *fp, const char *dest, struct stat *sb) ++static int create_copy (FILE *fp, const char *dest, struct stat *sb) +{ -+ struct utimbuf ub; -+ FILE *bkfp; -+ int c; -+ mode_t mask; ++ struct utimbuf ub; ++ FILE *bkfp; ++ int c; ++ mode_t mask; + -+ mask = umask(077); -+ bkfp = fopen(dest, "w"); -+ umask(mask); -+ if (!bkfp) return -1; ++ mask = umask (077); ++ bkfp = fopen (dest, "w"); ++ (void) umask (mask); ++ if (NULL == bkfp) { ++ return -1; ++ } + -+ rewind(fp); -+ while ((c = getc(fp)) != EOF) { -+ if (putc(c, bkfp) == EOF) break; -+ } ++ rewind (fp); ++ while ((c = getc (fp)) != EOF) { ++ if (putc (c, bkfp) == EOF) { ++ break; ++ } ++ } + -+ if (c != EOF || fflush(bkfp)) { -+ fclose(bkfp); -+ unlink(dest); -+ return -1; -+ } -+ if ( (fsync (fileno (bkfp)) != 0) -+ || (fclose(bkfp) != 0)) { -+ unlink(dest); -+ return -1; -+ } ++ if ( (c != EOF) ++ || (fflush (bkfp) != 0)) { ++ (void) fclose (bkfp); ++ (void) unlink (dest); ++ return -1; ++ } ++ if ( (fsync (fileno (bkfp)) != 0) ++ || (fclose (bkfp) != 0)) { ++ (void) unlink (dest); ++ return -1; ++ } + -+ ub.actime = sb->st_atime; -+ ub.modtime = sb->st_mtime; -+ if (utime(dest, &ub) || -+ chmod(dest, sb->st_mode) || -+ chown(dest, sb->st_uid, sb->st_gid)) { -+ unlink(dest); -+ return -1; -+ } -+ return 0; ++ ub.actime = sb->st_atime; ++ ub.modtime = sb->st_mtime; ++ if ( (utime (dest, &ub) != 0) ++ || (chmod (dest, sb->st_mode) != 0) ++ || (chown (dest, sb->st_uid, sb->st_gid) != 0)) { ++ (void) unlink (dest); ++ return -1; ++ } ++ return 0; +} + -+static void -+cppwexit(const char *msg, int syserr, int ret) ++static void cppwexit (const char *msg, int syserr, int ret) +{ -+ int err = errno; -+ if (filelocked) (*unlock)(); -+ if (msg) fprintf(stderr, "%s: %s", Prog, msg); -+ if (syserr) fprintf(stderr, ": %s", strerror(err)); -+ fprintf(stderr, "\n%s: %s is unchanged\n", Prog, filename); -+ exit(ret); ++ int err = errno; ++ if (filelocked) { ++ (*unlock) (); ++ } ++ if (NULL != msg) { ++ fprintf (stderr, "%s: %s", Prog, msg); ++ } ++ if (0 != syserr) { ++ fprintf (stderr, ": %s", strerror (err)); ++ } ++ fprintf (stderr, "\n%s: %s is unchanged\n", Prog, filename); ++ ++ exit (ret); +} + -+static void -+cppwcopy(const char *file, const char *in_file, int (*file_lock) (void), int (*file_unlock) (void)) ++static void cppwcopy (const char *file, ++ const char *in_file, ++ int (*file_lock) (void), ++ int (*file_unlock) (void)) +{ -+ struct stat st1; -+ FILE *f; -+ char filenew[1024]; ++ struct stat st1; ++ FILE *f; ++ char filenew[1024]; + -+ snprintf(filenew, sizeof filenew, "%s.new", file); -+ unlock = file_unlock; -+ filename = file; -+ filenewname = filenew; ++ snprintf (filenew, sizeof filenew, "%s.new", file); ++ unlock = file_unlock; ++ filename = file; ++ filenewname = filenew; + -+ if (access(file, F_OK)) cppwexit(file, 1, 1); -+ if (!file_lock()) cppwexit("Couldn't lock file", 0, 5); -+ filelocked = 1; ++ if (access (file, F_OK) != 0) { ++ cppwexit (file, 1, 1); ++ } ++ if (file_lock () == 0) { ++ cppwexit ("Couldn't lock file", 0, 5); ++ } ++ filelocked = true; + -+ /* file to copy has same owners, perm */ -+ if (stat(file, &st1)) cppwexit(file, 1, 1); -+ if (!(f = fopen(in_file, "r"))) cppwexit(in_file, 1, 1); -+ if (create_copy(f, filenew, &st1)) -+ cppwexit("Couldn't make copy", errno, 1); ++ /* file to copy has same owners, perm */ ++ if (stat (file, &st1) != 0) { ++ cppwexit (file, 1, 1); ++ } ++ f = fopen (in_file, "r"); ++ if (NULL == f) { ++ cppwexit (in_file, 1, 1); ++ } ++ if (create_copy (f, filenew, &st1) != 0) { ++ cppwexit ("Couldn't make copy", errno, 1); ++ } + -+ /* XXX - here we should check filenew for errors; if there are any, -+ fail w/ an appropriate error code and let the user manually fix -+ it. Use pwck or grpck to do the check. - Stephen (Shamelessly -+ stolen from '--marekm's comment) */ ++ /* XXX - here we should check filenew for errors; if there are any, ++ * fail w/ an appropriate error code and let the user manually fix ++ * it. Use pwck or grpck to do the check. - Stephen (Shamelessly ++ * stolen from '--marekm's comment) */ + -+ if (rename(filenew, file) == -1) { -+ fprintf(stderr, "%s: can't copy %s: %s)\n", -+ Prog, filenew, strerror(errno)); -+ cppwexit(0,0,1); -+ } ++ if (rename (filenew, file) != 0) { ++ fprintf (stderr, "%s: can't copy %s: %s)\n", ++ Prog, filenew, strerror (errno)); ++ cppwexit (0,0,1); ++ } + -+ (*file_unlock)(); ++ (*file_unlock) (); +} + -+ -+int -+main(int argc, char **argv) ++int main (int argc, char **argv) +{ -+ int flag; -+ int cpshadow = 0; -+ char *in_file; -+ char *c; -+ int e = 1; -+ int do_cppw; ++ int flag; ++ bool cpshadow = false; ++ char *in_file; ++ int e = E_USAGE; ++ bool do_cppw = true; + -+ Prog = ((c = strrchr(*argv, '/')) ? c+1 : *argv); -+ do_cppw = (strcmp(Prog, "cpgr") != 0); ++ Prog = Basename (argv[0]); ++ if (strcmp (Prog, "cpgr") != 0) { ++ do_cppw = false; ++ } + -+ while ((flag = getopt(argc, argv, "ghps")) != EOF) { -+ switch (flag) { -+ case 'p': -+ do_cppw = 1; -+ break; -+ case 'g': -+ do_cppw = 0; -+ break; -+ case 's': -+ cpshadow = 1; -+ break; -+ case 'h': -+ e = 0; -+ default: -+ printf("Usage:\n\ ++ while ((flag = getopt (argc, argv, "ghps")) != EOF) { ++ switch (flag) { ++ case 'p': ++ do_cppw = true; ++ break; ++ case 'g': ++ do_cppw = false; ++ break; ++ case 's': ++ cpshadow = true; ++ break; ++ case 'h': ++ e = E_SUCCESS; ++ /*pass through*/ ++ default: ++ (void) fputs ("Usage:\n\ +`cppw ' copys over /etc/passwd `cppw -s ' copys over /etc/shadow\n\ +`cpgr ' copys over /etc/group `cpgr -s ' copys over /etc/gshadow\n\ -+"); -+ exit(e); -+ } -+ } ++", (E_SUCCESS != e) ? stderr : stdout); ++ exit (e); ++ } ++ } + -+ if (optind >= argc) { -+ cppwexit ("missing file argument, -h for usage",0,1); -+ } ++ if (optind >= argc) { ++ cppwexit ("missing file argument, -h for usage",0,1); ++ } + -+ in_file = argv[argc - 1]; ++ in_file = argv[argc - 1]; + -+ if (do_cppw) { -+ if (cpshadow) -+ cppwcopy(SHADOW_FILE, in_file, spw_lock, spw_unlock); -+ else -+ cppwcopy(PASSWD_FILE, in_file, pw_lock, pw_unlock); -+ } -+ else { ++ if (do_cppw) { ++ if (cpshadow) { ++ cppwcopy (SHADOW_FILE, in_file, spw_lock, spw_unlock); ++ } else { ++ cppwcopy (PASSWD_FILE, in_file, pw_lock, pw_unlock); ++ } ++ } else { +#ifdef SHADOWGRP -+ if (cpshadow) -+ cppwcopy(SGROUP_FILE, in_file, sgr_lock, sgr_unlock); -+ else -+#endif -+ cppwcopy(GROUP_FILE, in_file, gr_lock, gr_unlock); -+ } ++ if (cpshadow) { ++ cppwcopy (SGROUP_FILE, in_file, sgr_lock, sgr_unlock); ++ } else ++#endif /* SHADOWGRP */ ++ { ++ cppwcopy (GROUP_FILE, in_file, gr_lock, gr_unlock); ++ } ++ } + -+ return 0; ++ return 0; +} ++ --- a/src/Makefile.am +++ b/src/Makefile.am @@ -26,6 +26,7 @@ diff --git a/debian/patches/402_cppw_selinux b/debian/patches/402_cppw_selinux index 77d0096e..ebd90745 100644 --- a/debian/patches/402_cppw_selinux +++ b/debian/patches/402_cppw_selinux @@ -17,46 +17,46 @@ Depends on 401_cppw_src.dpatch #include +#ifdef WITH_SELINUX +#include -+#endif ++#endif /* WITH_SELINUX */ + #include "exitcodes.h" #include "prototypes.h" #include "pwio.h" - #include "shadowio.h" -@@ -117,6 +120,22 @@ - filenewname = filenew; - - if (access(file, F_OK)) cppwexit(file, 1, 1); +@@ -134,6 +137,22 @@ + if (access (file, F_OK) != 0) { + cppwexit (file, 1, 1); + } +#ifdef WITH_SELINUX -+ /* if SE Linux is enabled then set the context of all new files -+ to be the context of the file we are editing */ -+ if (is_selinux_enabled () > 0) { -+ security_context_t passwd_context=NULL; -+ int ret = 0; -+ if (getfilecon (file, &passwd_context) < 0) { -+ cppwexit (_("Couldn't get file context"), errno, 1); -+ } -+ ret = setfscreatecon (passwd_context); -+ freecon (passwd_context); -+ if (0 != ret) { -+ cppwexit (_("setfscreatecon () failed"), errno, 1); -+ } -+ } -+#endif - if (!file_lock()) cppwexit("Couldn't lock file", 0, 5); - filelocked = 1; - -@@ -137,6 +156,15 @@ - cppwexit(0,0,1); - } ++ /* if SE Linux is enabled then set the context of all new files ++ * to be the context of the file we are editing */ ++ if (is_selinux_enabled () > 0) { ++ security_context_t passwd_context=NULL; ++ int ret = 0; ++ if (getfilecon (file, &passwd_context) < 0) { ++ cppwexit (_("Couldn't get file context"), errno, 1); ++ } ++ ret = setfscreatecon (passwd_context); ++ freecon (passwd_context); ++ if (0 != ret) { ++ cppwexit (_("setfscreatecon () failed"), errno, 1); ++ } ++ } ++#endif /* WITH_SELINUX */ + if (file_lock () == 0) { + cppwexit ("Couldn't lock file", 0, 5); + } +@@ -162,6 +181,15 @@ + cppwexit (0,0,1); + } +#ifdef WITH_SELINUX -+ /* unset the fscreatecon */ -+ if (is_selinux_enabled () > 0) { -+ if (setfscreatecon (NULL)) { -+ cppwexit (_("setfscreatecon() failed"), errno, 1); -+ } -+ } -+#endif ++ /* unset the fscreatecon */ ++ if (is_selinux_enabled () > 0) { ++ if (setfscreatecon (NULL)) { ++ cppwexit (_("setfscreatecon() failed"), errno, 1); ++ } ++ } ++#endif /* WITH_SELINUX */ + - (*file_unlock)(); + (*file_unlock) (); }