File manager - Edit - /home/ferretapmx/public_html/sos.tar
Back
AUTHORS 0000644 00000012004 15231153345 0005613 0 ustar 00 Individuals ----------- Aaron Conole <aconole@redhat.com> Abhijeet Kasurde <akasurde@redhat.com> Adam Stokes <adam.stokes@ubuntu.com> Adrien Kunysz <akunysz@acunu.com> Alan Pevec <apevec@redhat.com> Alexandru Juncu <alexj@linux.com> Ante Karamatic <ante.karamatic@canonical.com> Archit Sharma <arcsharm@redhat.com> Aruna Balakrishnaiah <aruna@linux.vnet.ibm.com> Assaf Muller <amuller@redhat.com> Ben Turner <bturner@redhat.com> Bharani C.V. <bharanve@linux.vnet.ibm.com> Bill Yodlowsky <byodlows@redhat.com> Brent Eagles <beagles@redhat.com> Bryan Quigley <bryan.quigley@canonical.com> Bryn M. Reeves <bmr@redhat.com> Chris J Arges <chris.j.arges@ubuntu.com> Chris Johnston <chrisjohnston@ubuntu.com> Chris Newcomer <chris.newcomer@canonical.com> Christy Perez <christy@linux.vnet.ibm.com> Coty Sutherland <csutherl@redhat.com> Dimitri John Ledkov <xnox@ubuntu.com> Eduardo Damato <eduardo.damato@canonical.com> Edward Hope-Morley <edward.hope-morley@canonical.com> Eoghan Glynn <eglynn@redhat.com> Eric Desrochers <eric.desrochers@canonical.com> Eric Rich <erich@redhat.com> Eric Williams <eric.williams@canonical.com> Eugene Teo <eteo@redhat.com> Felipe Reyes <felipe.reyes@canonical.com> Flaper Fesp <flaper87@gmail.com> Flavio Leitner <fbl@redhat.com> Flavio Percoco <fpercoco@redhat.com> Frank Ch. Eigler <fche@elastic.org> Gary Kotton <gkotton@redhat.com> Gaël Chamoulaud <gael.chamoulaud@gmail.com> Germano Veit Michel <germano@redhat.com> Guy Streeter <streeter@redhat.com> Günther Deschner <gd@samba.org> Harald Klein <hari@vt100.at> Hisanobu Okuda <hokuda@redhat.com> Jacob Wen <jian.w.wen@oracle.com> Jake Hunsaker <jhunsake@redhat.com> James Hunt <james.hunt@ubuntu.com> Jan Grant <jan.grant@hp.com> Jan Pokorný <jpokorny@redhat.com> Jeff Dutton <jeff.r.dutton@gmail.com> Jeff Peeler <jpeeler@redhat.com> Jeff Welch <whatthejeff@gmail.com> Jeremy Agee <jagee@redhat.com> Jeremy Crafts <jcrafts@redhat.com> Jeremy Eder <jeder@redhat.com> Jesse Jaggars <jjaggars@redhat.com> Jian Wen <jian.wen@canonical.com> Jiri Popelka <jpopelka@redhat.com> Jirka Hladky <jhladky@redhat.com> Joel Stanley <joel@jms.id.au> Joey Boggs <jboggs@redhat.com> John Berninger <jwb@redhat.com> John Haxby <john.haxby@oracle.com> Jon Magrini <jmagrini@redhat.com> Jon Stanley <jonstanley@gmail.com> Jorge Niedbalski <niedbalski@gmail.com> Jose Castillo <jcastillo@redhat.com> Justin Payne <jpayne@redhat.com> Justin Stephenson <jstephen@redhat.com> Kamalesh Babulal <kamalesh@linux.vnet.ibm.com> Keigo Noha <knoha@redhat.com> Keith Kearnan <kearnan_keith@emc.com> Keith Robertson <kroberts@redhat.com> Kenneth Koski <mechaxl@gmail.com> Kent Lamb <klamb@redhat.com> Kevin Traynor <ktraynor@redhat.com> Lee Yarwood <lyarwood@redhat.com> Leno Hou <lenohou@gmail.com> Louis Bouchard <louis.bouchard@canonical.com> Luca Miccini <luca.miccini@redhat.com> Luigi Toscano <ltoscano@redhat.com> Lukas Herbolt <lherbolt@redhat.com> Lukas Zapletal <lzap@redhat.com> Major Hayden <major@mhtx.net> Marc Sauton <msauton@redhat.com> Martin Frodl <mfrodl@redhat.com> Martin Schuppert <mschuppert@redhat.com> Michael Adam <obnox@samba.org> Michael Kerrin <michael.kerrin@hp.com> Michal Srb <msrb@redhat.com> Michele Baldessari <michele@acksyn.org> Mukesh Ojha <mukesh02@linux.vnet.ibm.com> Navid Sheikhol-Eslami <navid@redhat.com> Neependra Khare <nkhare@redhat.com> Nijin Ashok <nashok@redhat.com> Pablo Iranzo Gómez <Pablo.Iranzo@gmail.com> Patrick Talbert <ptalbert@redhat.com> Pavel Moravec <pmoravec@redhat.com> Pep Turro Mauri <pep@redhat.com> Peter Portante <peter.portante@redhat.com> Pierguido Lambri <plambri@redhat.com> Pierre Amadio <pamadio@redhat.com> Pierre Carrier <pcarrier@redhat.com> Piotr Drąg <piotrdrag@gmail.com> Poornima <pkshiras@redhat.com> Pratik Bandarkar <pbandark@redhat.com> Ranjith Rajaram <rrajaram@redhat.com> Raphael Badin <raphael.badin@canonical.com> Richard Brantley <brantleyr@gmail.com> Robb Manes <rmanes@redhat.com> Rohan Kanade <rkanade@redhat.com> Sachin <psachin@redhat.com> Sadique Puthen <sputhenp@redhat.com> Samuel Mendoza-Jonas <samjc.mj@gmail.com> Sandro Bonazzola <sbonazzo redhat com> Shane Bradley <sbradley@redhat.com> Shijoe George <spanjikk@redhat.com> Soumya Koduri <skoduri@redhat.com> Steve Conklin <sconklin@redhat.com> Tim Speetjens <tim.speetjens@redhat.com> Tomas Petr <tpetr@redhat.com> Tomas Smetana <tsmetana@redhat.com> Tomas Tomecek <ttomecek@redhat.com> Vasant Hegde <hegdevasant@linux.vnet.ibm.com> Xavier Queralt <xqueralt@redhat.com> Yedidyah Bar David <didi@redhat.com> amitg.b14@gmail.com <amitg.b14@gmail.com> galstrom21 <jshepher@rackspace.com> hari gowtham <hgowtham@redhat.com> jbainbri <jbainbri@redhat.com> jhjaggars <jhjaggars@gmail.com> mulhern <amulhern@redhat.com> ncoghlan <ncoghlan@gmail.com> qsn <sd@queasysnail.net> spandey <spandey@redhat.com> tanaka_733 <tanaka-takayoshi@users.noreply.github.com> tiwillia@redhat.com <tiwillia@redhat.com> Companies --------- Red Hat, Inc. Rackspace US, Inc. EMC Corporation Canonical, Ltd. IBM Corporation Hewlett-Packard Development Company, L.P. Oracle Corporation Organizations ------------- The Linux Foundation Samba README.md 0000644 00000006257 15231153345 0006037 0 ustar 00 [](https://travis-ci.org/sosreport/sos) # SoS Sos is an extensible, portable, support data collection tool primarily aimed at Linux distributions and other UNIX-like operating systems. This project is hosted at: * https://github.com/sosreport/sos For the latest version, to contribute, and for more information, please visit the project pages or join the mailing list. To clone the current master (development) branch run: ``` git clone git://github.com/sosreport/sos.git ``` ## Reporting bugs Please report bugs via the mailing list or by opening an issue in the [GitHub Issue Tracker][5] ## Mailing list The [sos-devel][4] is the mailing list for any sos-related questions and discussion. Patch submissions and reviews are welcome too. ## Patches and pull requests Patches can be submitted via the mailing list or as GitHub pull requests. If using GitHub please make sure your branch applies to the current master as a 'fast forward' merge (i.e. without creating a merge commit). Use the `git rebase` command to update your branch to the current master if necessary. Please refer to the [contributor guidelines][0] for guidance on formatting patches and commit messages. ## Documentation User and API [documentation][6] is automatically generated using [Sphinx][7] and [Read the Docs][8]. To generate HTML documents locally, install dependencies using ``` pip install -r requirements.txt ``` and run ``` make ``` Please run `make test` before sending a [pull request][0], or run the test suite manually using the `nosetests` command (ideally for the set of Python versions currently supported by `sos` upstream). ### Wiki * [How to write a plugin][1] * [How to write a policy][2] * [Plugin options][3] To help get your changes merged quickly with as few revisions as possible please refer to the [Contributor Guidelines][0] when submitting patches or pull requests. ## Installation ### Manual Installation You can simply run from the git checkout now: ``` $ sudo ./sosreport -a ``` Or, if you only have python3 installed: ``` $ sudo python3 ./sosreport -a ``` * Note: the `sosreport` command requires a configuration file: if no `sos.conf` is present in the `/etc` directory (i.e. no system installation of sos exists), use the `--config` option to provide one: ``` $ sudo python ./sosreport -a --config ./sos.conf ``` To install locally (as root): ``` # make install ``` To build an rpm: ``` $ make rpm ``` ### Pre-built Packaging Fedora/RHEL users install via yum: ``` yum install sos ``` Debian users install via apt: ``` apt install sosreport ``` Ubuntu (14.04 LTS and above) users install via apt: ``` sudo apt install sosreport ``` [0]: https://github.com/sosreport/sos/wiki/Contribution-Guidelines [1]: https://github.com/sosreport/sos/wiki/How-to-Write-a-Plugin [2]: https://github.com/sosreport/sos/wiki/How-to-Write-a-Policy [3]: https://github.com/sosreport/sos/wiki/Plugin-options [4]: https://www.redhat.com/mailman/listinfo/sos-devel [5]: https://github.com/sosreport/sos/issues?state=open [6]: https://sos.readthedocs.org/en/latest/index.html [7]: https://www.sphinx-doc.org/ [8]: https://www.readthedocs.org/ archive.py 0000644 00000064127 15231444714 0006556 0 ustar 00 # Copyright (C) 2012 Red Hat, Inc., # Jesse Jaggars <jjaggars@redhat.com> # Bryn M. Reeves <bmr@redhat.com> # # This file is part of the sos project: https://github.com/sosreport/sos # # This copyrighted material is made available to anyone wishing to use, # modify, copy, or redistribute it subject to the terms and conditions of # version 2 of the GNU General Public License. # # See the LICENSE file in the source distribution for further information. import os import tarfile import shutil import logging import codecs import errno import stat from threading import Lock from sos.utilities import sos_get_command_output, is_executable try: import selinux except ImportError: pass # PYCOMPAT import six if six.PY3: long = int P_FILE = "file" P_LINK = "link" P_NODE = "node" P_DIR = "dir" class Archive(object): """Abstract base class for archives.""" @classmethod def archive_type(cls): """Returns the archive class's name as a string. """ return cls.__name__ log = logging.getLogger("sos") _name = "unset" _debug = False _path_lock = Lock() def _format_msg(self, msg): return "[archive:%s] %s" % (self.archive_type(), msg) def set_debug(self, debug): self._debug = debug def log_error(self, msg): self.log.error(self._format_msg(msg)) def log_warn(self, msg): self.log.warning(self._format_msg(msg)) def log_info(self, msg): self.log.info(self._format_msg(msg)) def log_debug(self, msg): if not self._debug: return self.log.debug(self._format_msg(msg)) # this is our contract to clients of the Archive class hierarchy. # All sub-classes need to implement these methods (or inherit concrete # implementations from a parent class. def add_file(self, src, dest=None): raise NotImplementedError def add_string(self, content, dest, mode='w'): raise NotImplementedError def add_binary(self, content, dest): raise NotImplementedError def add_link(self, source, link_name): raise NotImplementedError def add_dir(self, path): raise NotImplementedError def add_node(self, path, mode, device): raise NotImplementedError def get_tmp_dir(self): """Return a temporary directory that clients of the archive may use to write content to. The content of the path is guaranteed to be included in the generated archive.""" raise NotImplementedError def name_max(self): """Return the maximum file name length this archive can support. This is the lesser of the name length limit of the archive format and any temporary file system based cache.""" raise NotImplementedError def get_archive_path(self): """Return a string representing the path to the temporary archive. For archive classes that implement in-line handling this will be the archive file itself. Archives that use a directory based cache prior to packaging should return the path to the temporary directory where the report content is located""" pass def cleanup(self): """Clean up any temporary resources used by an Archive class.""" pass def finalize(self, method): """Finalize an archive object via method. This may involve creating An archive that is subsequently compressed or simply closing an archive that supports in-line handling. If method is automatic then the following methods are tried in order: xz, bz2 and gzip""" self.close() class FileCacheArchive(Archive): """ Abstract superclass for archive types that use a temporary cache directory in the file system. """ _tmp_dir = "" _archive_root = "" _archive_name = "" def __init__(self, name, tmpdir, policy, threads, enc_opts, sysroot): self._name = name self._tmp_dir = tmpdir self._policy = policy self._threads = threads self.enc_opts = enc_opts self.sysroot = sysroot self._archive_root = os.path.join(tmpdir, name) with self._path_lock: os.makedirs(self._archive_root, 0o700) self.log_info("initialised empty FileCacheArchive at '%s'" % (self._archive_root,)) def dest_path(self, name): if os.path.isabs(name): name = name.lstrip(os.sep) return (os.path.join(self._archive_root, name)) def join_sysroot(self, path): if path.startswith(self.sysroot): return path if path[0] == os.sep: path = path[1:] return os.path.join(self.sysroot, path) def _make_leading_paths(self, src, mode=0o700): """Create leading path components The standard python `os.makedirs` is insufficient for our needs: it will only create directories, and ignores the fact that some path components may be symbolic links. :param src: The source path in the host file system for which leading components should be created, or the path to an sos_* virtual directory inside the archive. Host paths must be absolute (initial '/'), and sos_* directory paths must be a path relative to the root of the archive. :param mode: An optional mode to be used when creating path components. :returns: A rewritten destination path in the case that one or more symbolic links in intermediate components of the path have altered the path destination. """ self.log_debug("Making leading paths for %s" % src) root = self._archive_root dest = src def in_archive(path): """Test whether path ``path`` is inside the archive. """ return path.startswith(os.path.join(root, "")) if not src.startswith("/"): # Sos archive path (sos_commands, sos_logs etc.) src_dir = src else: # Host file path src_dir = (src if os.path.isdir(self.join_sysroot(src)) else os.path.split(src)[0]) # Build a list of path components in root-to-leaf order. path = src_dir path_comps = [] while path != '/' and path != '': head, tail = os.path.split(path) path_comps.append(tail) path = head path_comps.reverse() abs_path = root src_path = "/" # Check and create components as needed for comp in path_comps: abs_path = os.path.join(abs_path, comp) # Do not create components that are above the archive root. if not in_archive(abs_path): continue src_path = os.path.join(src_path, comp) if not os.path.exists(abs_path): self.log_debug("Making path %s" % abs_path) if os.path.islink(src_path) and os.path.isdir(src_path): target = os.readlink(src_path) # The directory containing the source in the host fs, # adjusted for the current level of path creation. target_dir = os.path.split(src_path)[0] # The source path of the target in the host fs to be # recursively copied. target_src = os.path.join(target_dir, target) # Recursively create leading components of target dest = self._make_leading_paths(target_src, mode=mode) dest = os.path.normpath(dest) # In case symlink target is an absolute path, make it # relative to the directory with symlink source if os.path.isabs(target): target = os.path.relpath(target, target_dir) self.log_debug("Making symlink '%s' -> '%s'" % (abs_path, target)) os.symlink(target, abs_path) else: self.log_debug("Making directory %s" % abs_path) os.mkdir(abs_path, mode) dest = src_path return dest def _check_path(self, src, path_type, dest=None, force=False): """Check a new destination path in the archive. Since it is possible for multiple plugins to collect the same paths, and since plugins can now run concurrently, it is possible for two threads to race in archive methods: historically the archive class only needed to test for the actual presence of a path, since it was impossible for another `Archive` client to enter the class while another method invocation was being dispatched. Deal with this by implementing a locking scheme for operations that modify the path structure of the archive, and by testing explicitly for conflicts with any existing content at the specified destination path. It is not an error to attempt to create a path that already exists in the archive so long as the type of the object to be added matches the type of object already found at the path. It is an error to attempt to re-create an existing path with a different path type (for example, creating a symbolic link at a path already occupied by a regular file). :param src: the source path to be copied to the archive :param path_type: the type of object to be copied :param dest: an optional destination path :param force: force file creation even if the path exists :returns: An absolute destination path if the path should be copied now or `None` otherwise """ dest = dest or self.dest_path(src) if path_type == P_DIR: dest_dir = dest else: dest_dir = os.path.split(dest)[0] if not dest_dir: return dest # Check containing directory presence and path type if os.path.exists(dest_dir) and not os.path.isdir(dest_dir): raise ValueError("path '%s' exists and is not a directory" % dest_dir) elif not os.path.exists(dest_dir): src_dir = src if path_type == P_DIR else os.path.split(src)[0] self._make_leading_paths(src_dir) def is_special(mode): return any([ stat.S_ISBLK(mode), stat.S_ISCHR(mode), stat.S_ISFIFO(mode), stat.S_ISSOCK(mode) ]) if force: return dest # Check destination path presence and type if os.path.exists(dest): # Use lstat: we care about the current object, not the referent. st = os.lstat(dest) ve_msg = "path '%s' exists and is not a %s" if path_type == P_FILE and not stat.S_ISREG(st.st_mode): raise ValueError(ve_msg % (dest, "regular file")) if path_type == P_LINK and not stat.S_ISLNK(st.st_mode): raise ValueError(ve_msg % (dest, "symbolic link")) if path_type == P_NODE and not is_special(st.st_mode): raise ValueError(ve_msg % (dest, "special file")) if path_type == P_DIR and not stat.S_ISDIR(st.st_mode): raise ValueError(ve_msg % (dest, "directory")) # Path has already been copied: skip return None return dest def add_file(self, src, dest=None): with self._path_lock: if not dest: dest = src dest = self._check_path(dest, P_FILE) if not dest: return # Handle adding a file from either a string respresenting # a path, or a File object open for reading. if not getattr(src, "read", None): # path case try: shutil.copy(src, dest) except IOError as e: # Filter out IO errors on virtual file systems. if src.startswith("/sys/") or src.startswith("/proc/"): pass else: self.log_info("caught '%s' copying '%s'" % (e, src)) except OSError as e: self.log_info("File not collected: '%s'" % e) # copy file attributes, skip SELinux xattrs for /sys and /proc try: stat = os.stat(src) if src.startswith("/sys/") or src.startswith("/proc/"): shutil.copymode(src, dest) os.utime(dest, ns=(stat.st_atime_ns, stat.st_mtime_ns)) else: shutil.copystat(src, dest) os.chown(dest, stat.st_uid, stat.st_gid) except Exception as e: self.log_debug("caught '%s' setting attributes of '%s'" % (e, dest)) file_name = "'%s'" % src else: # Open file case: first rewind the file to obtain # everything written to it. src.seek(0) with open(dest, "w") as f: for line in src: f.write(line) file_name = "open file" self.log_debug("added %s to FileCacheArchive '%s'" % (file_name, self._archive_root)) def add_string(self, content, dest, mode='w'): with self._path_lock: src = dest # add_string() is a special case: it must always take precedence # over any exixting content in the archive, since it is used by # the Plugin postprocessing hooks to perform regex substitution # on file content. dest = self._check_path(dest, P_FILE, force=True) f = codecs.open(dest, mode, encoding='utf-8') if isinstance(content, bytes): content = content.decode('utf8', 'ignore') f.write(content) if os.path.exists(src): try: shutil.copystat(src, dest) except OSError as e: self.log_error("Unable to add '%s' to archive: %s" % (dest, e)) self.log_debug("added string at '%s' to FileCacheArchive '%s'" % (src, self._archive_root)) def add_binary(self, content, dest): with self._path_lock: dest = self._check_path(dest, P_FILE) if not dest: return f = codecs.open(dest, 'wb', encoding=None) f.write(content) self.log_debug("added binary content at '%s' to archive '%s'" % (dest, self._archive_root)) def add_link(self, source, link_name): self.log_debug("adding symlink at '%s' -> '%s'" % (link_name, source)) with self._path_lock: dest = self._check_path(link_name, P_LINK) if not dest: return if not os.path.lexists(dest): os.symlink(source, dest) self.log_debug("added symlink at '%s' to '%s' in archive '%s'" % (dest, source, self._archive_root)) # Follow-up must be outside the path lock: we recurse into # other monitor methods that will attempt to reacquire it. self.log_debug("Link follow up: source=%s link_name=%s dest=%s" % (source, link_name, dest)) source_dir = os.path.dirname(link_name) host_path_name = os.path.realpath(os.path.join(source_dir, source)) dest_path_name = self.dest_path(host_path_name) def is_loop(link_name, source): """Return ``True`` if the symbolic link ``link_name`` is part of a file system loop, or ``False`` otherwise. """ link_dir = os.path.dirname(link_name) if not os.path.isabs(source): source = os.path.realpath(os.path.join(link_dir, source)) link_name = os.path.realpath(link_name) # Simple a -> a loop if link_name == source: return True # Find indirect loops (a->b-a) by stat()ing the first step # in the symlink chain try: os.stat(link_name) except OSError as e: if e.errno == 40: return True raise return False if not os.path.exists(dest_path_name): if os.path.islink(host_path_name): # Normalised path for the new link_name link_name = host_path_name # Containing directory for the new link dest_dir = os.path.dirname(link_name) # Relative source path of the new link source = os.path.join(dest_dir, os.readlink(host_path_name)) source = os.path.relpath(source, dest_dir) if is_loop(link_name, source): self.log_debug("Link '%s' - '%s' loops: skipping..." % (link_name, source)) return self.log_debug("Adding link %s -> %s for link follow up" % (link_name, source)) self.add_link(source, link_name) elif os.path.isdir(host_path_name): self.log_debug("Adding dir %s for link follow up" % source) self.add_dir(host_path_name) elif os.path.isfile(host_path_name): self.log_debug("Adding file %s for link follow up" % source) self.add_file(host_path_name) else: self.log_debug("No link follow up: source=%s link_name=%s" % (source, link_name)) self.log_debug("leaving add_link()") def add_dir(self, path): """Create a directory in the archive. :param path: the path in the host file system to add """ # Establish path structure with self._path_lock: self._check_path(path, P_DIR) def add_node(self, path, mode, device): dest = self._check_path(path, P_NODE) if not dest: return if not os.path.exists(dest): try: os.mknod(dest, mode, device) except OSError as e: if e.errno == errno.EPERM: msg = "Operation not permitted" self.log_info("add_node: %s - mknod '%s'" % (msg, dest)) return raise e shutil.copystat(path, dest) def name_max(self): if 'PC_NAME_MAX' in os.pathconf_names: pc_name_max = os.pathconf_names['PC_NAME_MAX'] return os.pathconf(self._archive_root, pc_name_max) else: return 255 def get_tmp_dir(self): return self._archive_root def get_archive_path(self): return self._archive_root def makedirs(self, path, mode=0o700): """Create path, including leading components. Used by sos.sosreport to set up sos_* directories. """ os.makedirs(os.path.join(self._archive_root, path), mode=mode) self.log_debug("created directory at '%s' in FileCacheArchive '%s'" % (path, self._archive_root)) def open_file(self, path): path = self.dest_path(path) return codecs.open(path, "r", encoding='utf-8', errors='ignore') def cleanup(self): if os.path.isdir(self._archive_root): shutil.rmtree(self._archive_root) def finalize(self, method): self.log_info("finalizing archive '%s' using method '%s'" % (self._archive_root, method)) self._build_archive() self.cleanup() self.log_info("built archive at '%s' (size=%d)" % (self._archive_name, os.stat(self._archive_name).st_size)) self.method = method try: res = self._compress() except Exception as e: exp_msg = "An error occurred compressing the archive: " self.log_error("%s %s" % (exp_msg, e)) return self.name() if self.enc_opts['encrypt']: try: return self._encrypt(res) except Exception as e: exp_msg = "An error occurred encrypting the archive:" self.log_error("%s %s" % (exp_msg, e)) return res else: return res def _encrypt(self, archive): """Encrypts the compressed archive using GPG. If encryption fails for any reason, it should be logged by sos but not cause execution to stop. The assumption is that the unencrypted archive would still be of use to the user, and/or that the end user has another means of securing the archive. Returns the name of the encrypted archive, or raises an exception to signal that encryption failed and the unencrypted archive name should be used. """ arc_name = archive.replace("sosreport-", "secured-sosreport-") arc_name += ".gpg" enc_cmd = "gpg --batch -o %s " % arc_name env = None if self.enc_opts["key"]: # need to assume a trusted key here to be able to encrypt the # archive non-interactively enc_cmd += "--trust-model always -e -r %s " % self.enc_opts["key"] enc_cmd += archive if self.enc_opts["password"]: # prevent change of gpg options using a long password, but also # prevent the addition of quote characters to the passphrase passwd = "%s" % self.enc_opts["password"].replace('\'"', '') env = {"sos_gpg": passwd} enc_cmd += "-c --passphrase-fd 0 " enc_cmd = "/bin/bash -c \"echo $sos_gpg | %s\"" % enc_cmd enc_cmd += archive r = sos_get_command_output(enc_cmd, timeout=0, env=env) if r["status"] == 0: return arc_name elif r["status"] == 2: if self.enc_opts["key"]: msg = "Specified key not in keyring" else: msg = "Could not read passphrase" else: # TODO: report the actual error from gpg. Currently, we cannot as # sos_get_command_output() does not capture stderr msg = "gpg exited with code %s" % r["status"] raise Exception(msg) class TarFileArchive(FileCacheArchive): """ archive class using python TarFile to create tar archives""" method = None _with_selinux_context = False def __init__(self, name, tmpdir, policy, threads, enc_opts, sysroot): super(TarFileArchive, self).__init__(name, tmpdir, policy, threads, enc_opts, sysroot) self._suffix = "tar" self._archive_name = os.path.join(tmpdir, self.name()) def set_tarinfo_from_stat(self, tar_info, fstat, mode=None): tar_info.mtime = fstat.st_mtime tar_info.pax_headers['atime'] = "%.9f" % fstat.st_atime tar_info.pax_headers['ctime'] = "%.9f" % fstat.st_ctime if mode: tar_info.mode = mode else: tar_info.mode = fstat.st_mode tar_info.uid = fstat.st_uid tar_info.gid = fstat.st_gid # this can be used to set permissions if using the # tarfile.add() interface to add directory trees. def copy_permissions_filter(self, tarinfo): orig_path = tarinfo.name[len(os.path.split(self._name)[-1]):] if not orig_path: orig_path = self._archive_root try: fstat = os.stat(orig_path) except OSError: return tarinfo if self._with_selinux_context: context = self.get_selinux_context(orig_path) if(context): tarinfo.pax_headers['RHT.security.selinux'] = context self.set_tarinfo_from_stat(tarinfo, fstat) return tarinfo def get_selinux_context(self, path): try: (rc, c) = selinux.getfilecon(path) return c except Exception: return None def name(self): return "%s.%s" % (self._name, self._suffix) def name_max(self): # GNU Tar format supports unlimited file name length. Just return # the limit of the underlying FileCacheArchive. return super(TarFileArchive, self).name_max() def _build_archive(self): tar = tarfile.open(self._archive_name, mode="w") # we need to pass the absolute path to the archive root but we # want the names used in the archive to be relative. tar.add(self._archive_root, arcname=os.path.split(self._name)[1], filter=self.copy_permissions_filter) tar.close() def _compress(self): methods = [] # Make sure that valid compression commands exist. for method in ['xz', 'bzip2', 'gzip']: if is_executable(method): methods.append(method) else: self.log_info("\"%s\" compression method unavailable" % method) if self.method in methods: methods = [self.method] exp_msg = "No compression utilities found." last_error = Exception(exp_msg) for cmd in methods: suffix = "." + cmd.replace('ip', '') cmd = self._policy.get_cmd_for_compress_method(cmd, self._threads) try: exec_cmd = "%s %s" % (cmd, self.name()) r = sos_get_command_output(exec_cmd, stderr=True, timeout=0) if r['status']: self.log_error(r['output']) raise Exception("%s exited with %s" % (exec_cmd, r['status'])) self._suffix += suffix return self.name() except Exception as e: last_error = e raise last_error # vim: set et ts=4 sw=4 : reporting.py 0000644 00000016641 15231444714 0007144 0 ustar 00 # Copyright (C) 2014 Red Hat, Inc., # Bryn M. Reeves <bmr@redhat.com> # # This file is part of the sos project: https://github.com/sosreport/sos # # This copyrighted material is made available to anyone wishing to use, # modify, copy, or redistribute it subject to the terms and conditions of # version 2 of the GNU General Public License. # # See the LICENSE file in the source distribution for further information. """ This provides a restricted tag language to define the sosreport index/report """ try: import json except ImportError: import simplejson as json # PYCOMPAT import six class Node(object): def __str__(self): return json.dumps(self.data) def can_add(self, node): return False class Leaf(Node): """Marker class that can be added to a Section node""" pass class Report(Node): """The root element of a report. This is a container for sections.""" def __init__(self): self.data = {} def can_add(self, node): return isinstance(node, Section) def add(self, *nodes): for node in nodes: if self.can_add(node): self.data[node.name] = node.data def _decode(s): """returns a string text for a given unicode/str input""" return (s if isinstance(s, six.text_type) else s.decode('utf8', 'ignore')) class Section(Node): """A section is a container for leaf elements. Sections may be nested inside of Report objects only.""" def __init__(self, name): self.name = _decode(name) self.data = {} def can_add(self, node): return isinstance(node, Leaf) def add(self, *nodes): for node in nodes: if self.can_add(node): self.data.setdefault(node.ADDS_TO, []).append(node.data) class Command(Leaf): ADDS_TO = "commands" def __init__(self, name, return_code, href): self.data = {"name": _decode(name), "return_code": return_code, "href": _decode(href)} class CopiedFile(Leaf): ADDS_TO = "copied_files" def __init__(self, name, href): self.data = {"name": _decode(name), "href": _decode(href)} class CreatedFile(Leaf): ADDS_TO = "created_files" def __init__(self, name, href): self.data = {"name": _decode(name), "href": _decode(href)} class Alert(Leaf): ADDS_TO = "alerts" def __init__(self, content): self.data = _decode(content) class Note(Leaf): ADDS_TO = "notes" def __init__(self, content): self.data = _decode(content) def ends_bs(string): """ Return True if 'string' ends with a backslash, and False otherwise. Define this as a named function for no other reason than that pep8 now forbids binding of a lambda expression to a name: 'E731 do not assign a lambda expression, use a def' """ return string.endswith('\\') class PlainTextReport(object): """Will generate a plain text report from a top_level Report object""" HEADER = "" FOOTER = "" LEAF = " * %(name)s" ALERT = " ! %s" NOTE = " * %s" PLUGLISTHEADER = "Loaded Plugins:" PLUGLISTITEM = " {name}" PLUGLISTSEP = "\n" PLUGLISTMAXITEMS = 5 PLUGLISTFOOTER = "" PLUGINFORMAT = "{name}" PLUGDIVIDER = "=" * 72 subsections = ( (Command, LEAF, "- commands executed:", ""), (CopiedFile, LEAF, "- files copied:", ""), (CreatedFile, LEAF, "- files created:", ""), (Alert, ALERT, "- alerts:", ""), (Note, NOTE, "- notes:", ""), ) line_buf = [] def __init__(self, report_node): self.report_data = sorted(six.iteritems(report_node.data)) def unicode(self): self.line_buf = line_buf = [] if (len(self.HEADER) > 0): line_buf.append(self.HEADER) # generate section/plugin list, split long list to multiple lines line_buf.append(self.PLUGLISTHEADER) line = "" i = 0 plugcount = len(self.report_data) for section_name, _ in self.report_data: line += self.PLUGLISTITEM.format(name=section_name) i += 1 if (i % self.PLUGLISTMAXITEMS == 0) and (i < plugcount): line += self.PLUGLISTSEP line += self.PLUGLISTFOOTER line_buf.append(line) for section_name, section_contents in self.report_data: line_buf.append(self.PLUGDIVIDER) line_buf.append(self.PLUGINFORMAT.format(name=section_name)) for type_, format_, header, footer in self.subsections: self.process_subsection(section_contents, type_.ADDS_TO, header, format_, footer) if (len(self.FOOTER) > 0): line_buf.append(self.FOOTER) # Workaround python.six mishandling of strings ending in '/' by # adding a single space following any '\' at end-of-line. # See Six issue #60. line_buf = [line + " " if ends_bs(line) else line for line in line_buf] output = u'\n'.join(map(lambda i: (i if isinstance(i, six.text_type) else i.decode('utf8', 'ignore')), line_buf)) if six.PY3: return output else: return output.encode('utf8') def process_subsection(self, section, key, header, format_, footer): if key in section: self.line_buf.append(header) for item in section.get(key): self.line_buf.append(format_ % item) if (len(footer) > 0): self.line_buf.append(footer) class HTMLReport(PlainTextReport): """Will generate a HTML report from a top_level Report object""" HEADER = """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Sos System Report</title> <style type="text/css"> td { padding: 0 5px; } </style> </head> <body>\n""" FOOTER = "</body></html>" LEAF = '<li><a href="%(href)s">%(name)s</a></li>' ALERT = "<li>%s</li>" NOTE = "<li>%s</li>" PLUGLISTHEADER = "<h3>Loaded Plugins:</h3><table><tr>" PLUGLISTITEM = '<td><a href="#{name}">{name}</a></td>\n' PLUGLISTSEP = "</tr>\n<tr>" PLUGLISTMAXITEMS = 5 PLUGLISTFOOTER = "</tr></table>" PLUGINFORMAT = '<h2 id="{name}">Plugin <em>{name}</em></h2>' PLUGDIVIDER = "<hr/>\n" subsections = ( (Command, LEAF, "<p>Commands executed:</p><ul>", "</ul>"), (CopiedFile, LEAF, "<p>Files copied:</p><ul>", "</ul>"), (CreatedFile, LEAF, "<p>Files created:</p><ul>", "</ul>"), (Alert, ALERT, "<p>Alerts:</p><ul>", "</ul>"), (Note, NOTE, "<p>Notes:</p><ul>", "</ul>"), ) class JSONReport(PlainTextReport): """Will generate a JSON report from a top_level Report object""" def unicode(self): output = json.dumps(self.report_data, indent=4, ensure_ascii=False) if six.PY3: return output else: return output.encode('utf8') # vim: set et ts=4 sw=4 : policies/amazon.pyc 0000644 00000002410 15231444714 0010357 0 ustar 00 � )rjc @ sL d d l m Z d d l m Z m Z d d l Z d e f d � � YZ d S( i����( t print_function( t RedHatPolicyt OS_RELEASENt AmazonPolicyc B s5 e Z d Z d Z d Z d d � Z e d � � Z RS( s Amazon Linuxt Amazons https://aws.amazon.comc C s t t | � j d | � d S( Nt sysroot( t superR t __init__( t selfR ( ( s7 /usr/lib/python2.7/site-packages/sos/policies/amazon.pyR s c C se t j j t � s t St t d � �: } x0 | D]( } | j d � r/ d | k rW t Sq/ q/ WWd QXt S( Nt rt NAMEs Amazon Linux( t ost patht existsR t Falset opent startswitht True( t clst ft line( ( s7 /usr/lib/python2.7/site-packages/sos/policies/amazon.pyt check s N( t __name__t __module__t distrot vendort vendor_urlt NoneR t classmethodR ( ( ( s7 /usr/lib/python2.7/site-packages/sos/policies/amazon.pyR s ( t __future__R t sos.policies.redhatR R R R ( ( ( s7 /usr/lib/python2.7/site-packages/sos/policies/amazon.pyt <module> s policies/redhat.pyo 0000644 00000053522 15231444714 0010367 0 ustar 00 � )rjc @ s� d d l m Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l m Z d d l m Z m Z d d l m Z m Z m Z d d l m Z d d l m Z e j d � Z y d d l Z e Z Wn e k r� e Z n Xd Z y e Z Wn e k rn Xd e f d � � YZ d Z d Z! e d e � Z"