// // aegis - project change supervisor // Copyright (C) 2006-2008, 2010, 2012, 2014 Peter Miller // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 3 of the License, or (at // your option) any later version. // // This program 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, see . // #include #include #include #include #include #include #include #include validation_files_text::~validation_files_text() { } validation_files_text::validation_files_text() { } validation::pointer validation_files_text::create(void) { return pointer(new validation_files_text()); } bool validation_files_text::check_binaries(void) const { return false; } bool validation_files_text::check(change::pointer cp, fstate_src_ty *src) { // // Note: we return true if the file is acceptable to the policy // (i.e. has no NUL characters). We return false if the file is // unacceptable (is binary). // // We aren't trusting libmagic for this one, just in case it only // looks at the beginning of the file (many implementations do). // nstring path(cp->file_path(src)); assert(!path.empty()); if (path.empty()) return true; os_become_orig(); bool result = true; input::pointer ip = input_file::open(path); for (;;) { int c = ip->getch(); if (c < 0) break; if (c == 0) { result = false; break; } } ip.reset(); os_become_undo(); if (!result) { sub_context_ty sc; sc.var_set_string("File_Name", src->file_name); change_error(cp, &sc, i18n("$filename: is binary")); } return result; } // vim: set ts=8 sw=4 et :