aboutsummaryrefslogtreecommitdiff
path: root/0.8.0/src/adjutrix/find_insecure_packages.cc
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-10-11 20:56:59 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-10-11 20:56:59 +0000
commite3b86134db7baada7b3a1e779e7d6d046ab53a1a (patch)
tree6acb3c0de68e1b95dbba8f0e00f770b8f31e4bac /0.8.0/src/adjutrix/find_insecure_packages.cc
parentab9cdb1150d97449e857cd55fe706377c9ab2422 (diff)
downloadpaludis-0.8.0.tar.gz
paludis-0.8.0.tar.xz
Tag release 0.8.00.8.0
Diffstat (limited to '0.8.0/src/adjutrix/find_insecure_packages.cc')
-rw-r--r--0.8.0/src/adjutrix/find_insecure_packages.cc162
1 files changed, 162 insertions, 0 deletions
diff --git a/0.8.0/src/adjutrix/find_insecure_packages.cc b/0.8.0/src/adjutrix/find_insecure_packages.cc
new file mode 100644
index 0000000..1409c69
--- /dev/null
+++ b/0.8.0/src/adjutrix/find_insecure_packages.cc
@@ -0,0 +1,162 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 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 "find_insecure_packages.hh"
+#include "command_line.hh"
+
+#include <paludis/util/tokeniser.hh>
+#include <paludis/util/compare.hh>
+
+#include <set>
+#include <map>
+#include <iostream>
+#include <iomanip>
+#include <algorithm>
+
+using namespace paludis;
+using std::cout;
+using std::cerr;
+using std::endl;
+
+namespace
+{
+ const unsigned col_width_package = 30;
+ const unsigned col_width_id = 40;
+
+ void
+ write_repository_header(const RepositoryName & repo)
+ {
+ std::string s("Insecure packages from advisories in repository '" + stringify(repo) + "'");
+ cout << std::string(s.length(), '=') << endl;
+ cout << s << endl;
+ cout << std::string(s.length(), '=') << endl;
+ cout << endl;
+
+ cout << std::left
+ << std::setw(col_width_package) << "package"
+ << std::setw(col_width_id) << "GLSA IDs"
+ << endl;
+
+ cout
+ << std::string(col_width_package - 1, '-') << " "
+ << std::string(col_width_id - 1, '-') << " "
+ << endl;
+ }
+
+ class ListInsecureVisitor :
+ public DepAtomVisitorTypes::ConstVisitor
+ {
+ private:
+ const Environment & _env;
+ std::multimap<PackageDatabaseEntry, std::string> _found;
+
+ public:
+ ListInsecureVisitor(const Environment & e) :
+ _env(e)
+ {
+ }
+
+ void visit(const AllDepAtom * const a)
+ {
+ std::for_each(a->begin(), a->end(), accept_visitor(this));
+ }
+
+ void visit(const AnyDepAtom * const a)
+ {
+ std::for_each(a->begin(), a->end(), accept_visitor(this));
+ }
+
+ void visit(const UseDepAtom * const a)
+ {
+ std::for_each(a->begin(), a->end(), accept_visitor(this));
+ }
+
+ void visit(const PackageDepAtom * const a)
+ {
+ PackageDatabaseEntryCollection::ConstPointer insecure(
+ _env.package_database()->query(*a, is_either));
+ for (PackageDatabaseEntryCollection::Iterator i(insecure->begin()),
+ i_end(insecure->end()) ; i != i_end ; ++i)
+ if (a->tag())
+ _found.insert(std::make_pair(*i, a->tag()->short_text()));
+ else
+ throw InternalError(PALUDIS_HERE, "didn't get a tag");
+ }
+
+ void visit(const PlainTextDepAtom * const)
+ {
+ }
+
+ void visit(const BlockDepAtom * const)
+ {
+ }
+
+ friend std::ostream & operator<< (std::ostream &, const ListInsecureVisitor &);
+ };
+
+ std::ostream & operator<< (std::ostream & s, const ListInsecureVisitor & v)
+ {
+ QualifiedPackageName old_name("dormouse/teapot");
+ for (std::multimap<PackageDatabaseEntry, std::string>::const_iterator
+ f(v._found.begin()), f_end(v._found.end()) ; f != f_end ; ++f)
+ {
+ if (f->first.name != old_name)
+ s << std::setw(col_width_package) << (stringify(f->first.name) + " ") << endl;
+ old_name = f->first.name;
+ s << std::setw(col_width_package) << (" " + stringify(f->first.version) + " ")
+ << f->second;
+ while (next(f) != f_end)
+ {
+ if (next(f)->first != f->first)
+ break;
+ cout << " " << f->second;
+ ++f;
+ }
+ cout << endl;
+ }
+
+ return s;
+ }
+}
+
+void do_find_insecure_packages(const Environment & env)
+{
+ Context context("When performing find-insecure-packages action:");
+
+ for (IndirectIterator<PackageDatabase::RepositoryIterator, const Repository>
+ r(env.package_database()->begin_repositories()),
+ r_end(env.package_database()->end_repositories()) ; r != r_end ; ++r)
+ {
+ if (r->name() == RepositoryName("virtuals"))
+ continue;
+
+ if (! r->sets_interface)
+ continue;
+
+ write_repository_header(r->name());
+
+ DepAtom::ConstPointer all_insecure(r->sets_interface->package_set("insecurity"));
+ if (! all_insecure)
+ continue;
+ ListInsecureVisitor v(env);
+ all_insecure->accept(&v);
+ cout << v << endl;
+ }
+}
+