]> thyrsus.com Git - coverity-submit.git/commitdiff
Fix insecure config file permissions.
authorEric S. Raymond <esr@thyrsus.com>
Wed, 4 Jun 2014 17:25:16 +0000 (13:25 -0400)
committerEric S. Raymond <esr@thyrsus.com>
Wed, 4 Jun 2014 17:25:16 +0000 (13:25 -0400)
NEWS
coverity-submit
coverity-submit.xml

diff --git a/NEWS b/NEWS
index 05518924c5ff79db5ec6227bbb9471a5f4fd27e7..4e96fb8abf23900d9ffe6687909f543c00410f68 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,7 @@
 
 Repository head:
     Documentation improvements. Code audited with new, stricter pylint.
+    Insecure positions on your configuration file are automatically fixed.
 
 1.11 @ 2013-09-27
     Fix buggy Mercurial commit-id method.
index 909288610e0ed0e077e272674e790b8f5a4cc45c..cbacfe6e47443d758de9f717bb8ece66f37cd142 100755 (executable)
@@ -6,7 +6,8 @@
 #
 from __future__ import print_function
 
-import os, pwd, sys, ConfigParser, getopt, tempfile, shutil, datetime, commands
+import os, pwd, sys, stat
+import ConfigParser, getopt, tempfile, shutil, datetime, commands
 
 version = "1.12"
 
@@ -48,17 +49,27 @@ def deduce_userid():
 if __name__ == '__main__':
     name = email = project = token = url = None
 
-    config = ConfigParser.RawConfigParser()
-    if os.path.exists(os.path.expanduser("~/.config/coverity-submit")):
-        config.read(os.path.expanduser("~/.config/coverity-submit"))
-    else:
-        config.read(os.path.expanduser("~/.coverity-submit"))
+    cfgpaths = [os.path.expanduser(x)
+                for x in ("~/.config/coverity-submit", "~/.coverity-submit")
+                if  os.path.exists(os.path.expanduser(x))]
+
+    # Security fix
+    for path in cfgpaths:
+        if stat.S_IMODE(os.stat(path).st_mode) != (stat.S_IRUSR | stat.S_IWUSR):
+            sys.stderr.write("coverity-submit: fixing insecure permissions.\n")
+            os.chmod(path, stat.S_IRUSR | stat.S_IWUSR)
 
     def die(complaint):
-        sys.stderr.write(complaint + "\n")
+        sys.stderr.write("coverity-submit: " + complaint + "\n")
         sys.exit(1)
 
-    # Gather information that is not project-specific
+    if len(cfgpaths) == 2:
+        die("Multiple configuration files.")
+    config = ConfigParser.RawConfigParser()
+    if len(cfgpaths) == 1:
+        config.read(cfgpaths[0])
+
+     # Gather information that is not project-specific
     if not "ALL" in config.sections():
         config.add_section("ALL")
     if not config.has_option("ALL", "name"):
index 32122eef98209d5895129e78d7c6f547a3d2c2a2..b83f22745c2d180cfc33418d6c8a3b00ae2c46c2 100644 (file)
@@ -113,6 +113,12 @@ matches a project, it is selected. Otherwise, a command-line argument
 can specify the project name; it is a fatal error for the argument, if
 given, not to match the name of one of the configured project profiles.</para>
 
+<para>Note: because your configuration file contains privileged
+information (the per-project Coverity authentication tokens) it should
+not have read or write permissions for anyone but its owner set. When
+<application>coverity-submit</application> detects such insecure
+permissions, it will fix them (telling you it is doing so).</para>
+
 <para>The <option>-n</option> option says to display all the commands that
 would be run without actually executing them. The <option>-v</option> option 
 enables slightly more verbose progress messages, and copies the Coverity