aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-02-16 17:31:54 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-02-16 17:31:54 +0000
commit510ac7c3fe551629dff0bf6eca72e865cf455237 (patch)
treebe0548c67bde795e1c01926c84b268d3234944f6
parent346f6fa569a93164e8967f165d49474565fd18a0 (diff)
downloadpaludis-510ac7c3fe551629dff0bf6eca72e865cf455237.tar.gz
paludis-510ac7c3fe551629dff0bf6eca72e865cf455237.tar.xz
Check for ROOT abuse. Fixes: ticket:106
-rw-r--r--paludis/qa/file_check.cc4
-rw-r--r--paludis/qa/files.m41
-rw-r--r--paludis/qa/root_check.cc106
-rw-r--r--paludis/qa/root_check.hh53
4 files changed, 163 insertions, 1 deletions
diff --git a/paludis/qa/file_check.cc b/paludis/qa/file_check.cc
index 4b22f53..b0f5f1a 100644
--- a/paludis/qa/file_check.cc
+++ b/paludis/qa/file_check.cc
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2006 Ciaran McCreesh <ciaranm@ciaranm.org>
+ * Copyright (c) 2006, 2007 Ciaran McCreesh <ciaranm@ciaranm.org>
*
* This file is part of the Paludis package manager. Paludis is free software;
* you can redistribute it and/or modify it under the terms of the GNU General
@@ -27,6 +27,7 @@
#include <paludis/qa/header_check.hh>
#include <paludis/qa/metadata_check.hh>
#include <paludis/qa/subshell_die_check.hh>
+#include <paludis/qa/root_check.hh>
#include <paludis/qa/variable_assigns_check.hh>
#include <paludis/qa/whitespace_check.hh>
@@ -52,6 +53,7 @@ FileCheckMaker::FileCheckMaker()
register_maker(Glep31Check::identifier(), &MakeFileCheck<Glep31Check>::make_file_check);
register_maker(HeaderCheck::identifier(), &MakeFileCheck<HeaderCheck>::make_file_check);
register_maker(MetadataCheck::identifier(), &MakeFileCheck<MetadataCheck>::make_file_check);
+ register_maker(RootCheck::identifier(), &MakeFileCheck<RootCheck>::make_file_check);
register_maker(SubshellDieCheck::identifier(), &MakeFileCheck<SubshellDieCheck>::make_file_check);
register_maker(VariableAssignsCheck::identifier(), &MakeFileCheck<VariableAssignsCheck>::make_file_check);
register_maker(WhitespaceCheck::identifier(), &MakeFileCheck<WhitespaceCheck>::make_file_check);
diff --git a/paludis/qa/files.m4 b/paludis/qa/files.m4
index 2c77298..eb1b05e 100644
--- a/paludis/qa/files.m4
+++ b/paludis/qa/files.m4
@@ -55,6 +55,7 @@ add(`profiles_check', `hh', `cc')
add(`qa_environment', `hh', `cc', `test', `testscript', `sr')
add(`repo_name_check', `hh', `cc')
add(`restrict_check', `hh', `cc')
+add(`root_check', `hh', `cc')
add(`src_uri_check', `hh', `cc')
add(`pdepend_overlap_check', `hh', `cc')
add(`qa', `hh', `cc')
diff --git a/paludis/qa/root_check.cc b/paludis/qa/root_check.cc
new file mode 100644
index 0000000..a32e400
--- /dev/null
+++ b/paludis/qa/root_check.cc
@@ -0,0 +1,106 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2007 Ciaran McCreesh <ciaranm@ciaranm.org>
+ *
+ * This file is part of the Paludis package manager. Paludis is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU General
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <fstream>
+#include <paludis/qa/root_check.hh>
+#include <paludis/util/is_file_with_extension.hh>
+#include <paludis/util/strip.hh>
+#include <pcre++.h>
+
+using namespace paludis;
+using namespace paludis::qa;
+
+namespace
+{
+ enum State
+ {
+ st_default,
+ st_in_src
+ };
+}
+
+RootCheck::RootCheck()
+{
+}
+
+CheckResult
+RootCheck::operator() (const FSEntry & f) const
+{
+ CheckResult result(f, identifier());
+
+ static pcrepp::Pcre::Pcre r_root("\\$[{]?ROOT[}]?([^=a-zA-Z0-9]|$)");
+ static pcrepp::Pcre::Pcre r_start("^src_");
+ static pcrepp::Pcre::Pcre r_end("^}");
+
+ if (! f.is_regular_file())
+ result << Message(qal_skip, "Not a regular file");
+ else if (! IsFileWithExtension(".ebuild")(f))
+ result << Message(qal_skip, "Not an ebuild file");
+ else
+ {
+ std::ifstream ff(stringify(f).c_str());
+ if (! ff)
+ result << Message(qal_major, "Can't read file");
+ else
+ {
+ State state(st_default);
+ std::string line;
+ unsigned line_number(0);
+
+ while (std::getline(ff, line))
+ {
+ ++line_number;
+
+ switch (state)
+ {
+ case st_default:
+ {
+ if (r_start.search(line))
+ state = st_in_src;
+ }
+ continue;
+
+ case st_in_src:
+ {
+ if (r_end.search(line))
+ state = st_default;
+ else if (r_root.search(line))
+ result << Message(qal_maybe, "Apparent ROOT abuse on line "
+ + stringify(line_number) + ": " + strip_leading(line, " \t"));
+ }
+ continue;
+ }
+
+ throw InternalError(PALUDIS_HERE, "bad state");
+ }
+ }
+ }
+
+ return result;
+}
+
+const std::string &
+RootCheck::identifier()
+{
+ static const std::string id("root");
+ return id;
+}
+
+
+
diff --git a/paludis/qa/root_check.hh b/paludis/qa/root_check.hh
new file mode 100644
index 0000000..2d85956
--- /dev/null
+++ b/paludis/qa/root_check.hh
@@ -0,0 +1,53 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2007 Ciaran McCreesh <ciaranm@ciaranm.org>
+ *
+ * This file is part of the Paludis package manager. Paludis is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU General
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef PALUDIS_GUARD_PALUDIS_QA_ROOT_CHECK_HH
+#define PALUDIS_GUARD_PALUDIS_QA_ROOT_CHECK_HH 1
+
+#include <paludis/qa/file_check.hh>
+
+namespace paludis
+{
+ namespace qa
+ {
+ /**
+ * QA check: abuse of ROOT.
+ *
+ * \ingroup grpqacheck
+ */
+ class RootCheck :
+ public FileCheck
+ {
+ public:
+ RootCheck();
+
+ CheckResult operator() (const FSEntry &) const;
+
+ static const std::string & identifier();
+
+ virtual std::string describe() const
+ {
+ return "Checks for abuse of ROOT";
+ }
+ };
+ }
+
+}
+
+#endif