]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
login-utils: verify writing to streams was successful
authorSami Kerola <kerolasa@iki.fi>
Wed, 4 Apr 2012 17:58:34 +0000 (19:58 +0200)
committerSami Kerola <kerolasa@iki.fi>
Wed, 4 Apr 2012 17:58:34 +0000 (19:58 +0200)
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
login-utils/chfn.c
login-utils/chsh.c
login-utils/islocal.c
login-utils/last.c
login-utils/logindefs.c
login-utils/newgrp.c
login-utils/setpwnam.c
login-utils/sulogin.c
login-utils/vipw.c

index 2d9a092cb319ff7f51a7e8670312ee409472de57..02014c7cee9805a0d99fad95afed59cfd1909545 100644 (file)
@@ -33,6 +33,7 @@
 
 #include "c.h"
 #include "env.h"
+#include "closestream.h"
 #include "islocal.h"
 #include "nls.h"
 #include "pamfail.h"
@@ -96,6 +97,7 @@ int main(int argc, char **argv)
        setlocale(LC_ALL, "");  /* both for messages and for iscntrl() below */
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
+       atexit(close_stdout);
 
        /*
         *  "oldf" contains the users original finger information.
index 4f0615c082e3014e4c716cc2860ff615f80c0560..7d944e19f058da303433bdeb69a51c9dd5903a85 100644 (file)
@@ -34,6 +34,7 @@
 
 #include "c.h"
 #include "env.h"
+#include "closestream.h"
 #include "islocal.h"
 #include "nls.h"
 #include "pamfail.h"
@@ -82,6 +83,7 @@ int main(int argc, char **argv)
        setlocale(LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
+       atexit(close_stdout);
 
        uid = getuid();
        memset(&info, 0, sizeof(info));
index 91dda0d29fa31035273a2cc7508435abd5ac446c..e23ca44e0bc1a8e8a068cd9df10b691bbc7cd6d4 100644 (file)
@@ -22,6 +22,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+#include "closestream.h"
 #include "islocal.h"
 #include "nls.h"
 #include "pathnames.h"
@@ -94,6 +95,7 @@ int is_local(const char *user)
 #ifdef TEST_PROGRAM
 int main(int argc, char *argv[])
 {
+       atexit(close_stdout);
        if (argc <= 2) {
                fprintf(stderr, "usage: %s <passwdfile> <username> [...]\n",
                        argv[0]);
index 417314ee596a0f7d12a75e96c4799d7325541f3c..34558bb9d3a5b6667b1e85d801da39626b8de11e 100644 (file)
@@ -56,6 +56,7 @@
 #include <netinet/in.h>
 #include <arpa/inet.h>
 
+#include "closestream.h"
 #include "pathnames.h"
 #include "nls.h"
 #include "xalloc.h"
@@ -121,6 +122,7 @@ main(int argc, char **argv) {
        setlocale(LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
+       atexit(close_stdout);
 
        while ((ch = getopt(argc, argv, "0123456789yli:f:h:t:")) != -1)
                switch((char)ch) {
index 7b801cf70f089f13f835e859320090761015b265..ff7266ea1d9c57e172f8d139a7fc0323c4eb9480 100644 (file)
@@ -29,6 +29,7 @@
 #include <sys/syslog.h>
 
 #include "c.h"
+#include "closestream.h"
 #include "logindefs.h"
 #include "nls.h"
 #include "pathnames.h"
@@ -252,6 +253,7 @@ int logindefs_setenv(const char *name, const char *conf, const char *dflt)
 int main(int argc, char *argv[])
 {
        char *name, *type;
+       atexit(close_stdout);
 
        if (argc <= 1)
                errx(EXIT_FAILURE, "usage: %s <filename> "
index 707c5893a88220941e05fe84c0ab7d79c841d7e5..4f6de12a14aea9a6ecd90900e0025c200c752f9f 100644 (file)
@@ -29,6 +29,7 @@
 #endif
 
 #include "c.h"
+#include "closestream.h"
 #include "nls.h"
 #include "pathnames.h"
 
@@ -132,6 +133,7 @@ int main(int argc, char *argv[])
        setlocale(LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
+       atexit(close_stdout);
 
        while ((ch = getopt_long(argc, argv, "Vh", longopts, NULL)) != -1)
                switch (ch) {
index 7459fe29852e06aedb2a14686f10351ba5c37fbd..ba15bc1317b890f4260605d891295f530c6bfc54 100644 (file)
@@ -59,7 +59,7 @@
 #include <unistd.h>
 
 #include "c.h"
-#include "fileutils.h"
+#include "closestream.h"
 #include "setpwnam.h"
 
 static void pw_init(void);
@@ -143,9 +143,7 @@ int setpwnam(struct passwd *pwd)
        /* xfmkstemp is too restrictive by default for passwd file */
        if (fchmod(fileno(fp), 0644) < 0)
                goto fail;
-       rc = fclose(fp);
-       fp = NULL;
-       if (rc < 0)
+       if (close_stream(fp) != 0)
                goto fail;
 
        fclose(pwf);    /* I don't think I want to know if this failed */
index 616442ee49325b18bd34a8bdb9cb1892aae091fc..ee725b58864dfa7d84b701bdbdc1d47a9394acb6 100644 (file)
@@ -47,6 +47,7 @@
 #endif
 
 #include "c.h"
+#include "closestream.h"
 #include "nls.h"
 #include "pathnames.h"
 #include "strutils.h"
@@ -476,6 +477,7 @@ int main(int argc, char **argv)
        setlocale(LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
+       atexit(close_stdout);
 
        /*
         * See if we have a timeout flag.
index 29e485cc46516807f1369b4f8a046039be956527..2d16999d28bcd001515d592165b92f6b90b00805 100644 (file)
@@ -72,7 +72,7 @@
 #include <unistd.h>
 
 #include "c.h"
-#include "fileutils.h"
+#include "closestream.h"
 #include "nls.h"
 #include "setpwnam.h"
 #include "strutils.h"
@@ -283,7 +283,8 @@ static void edit_file(int is_shadow)
                ch_ret = fchmod(fileno(tmp_fd), 0400);
        if (ch_ret < 0)
                err(EXIT_FAILURE, "%s: %s", _("cannot chmod file"), orig_file);
-       fclose(tmp_fd);
+       if (close_stream(tmp_fd) != 0)
+               err(EXIT_FAILURE, _("write error"));
        pw_write();
        close(passwd_file);
        ulckpwdf();
@@ -294,6 +295,7 @@ int main(int argc, char *argv[])
        setlocale(LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
+       atexit(close_stdout);
 
        if (!strcmp(program_invocation_short_name, "vigr")) {
                program = VIGR;