Skip to content

Commit

Permalink
Change directory structure.
Browse files Browse the repository at this point in the history
- This is a large change that moves most grr code under a grr subdirectory. This
  is necessary for python package building.
- This commit also contains lots of other development/bugfixing work we have
  been holding off on pushing since we're bumping the version number.

Don't use this commit in production, wait for the pending release.
  • Loading branch information
destijl committed Apr 5, 2016
1 parent f5adca8 commit a1479d8
Show file tree
Hide file tree
Showing 1,441 changed files with 25,687 additions and 8,459 deletions.
17 changes: 17 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
include requirements.txt

recursive-include * *
recursive-include gui *

recursive-exclude .git *
recursive-exclude build *
recursive-exclude dist *
recursive-exclude vagrant *
recursive-exclude travis *
recursive-exclude test_data *
recursive-exclude executables *.zip
recursive-exclude executables/windows/installers *.exe
recursive-exclude executables *.bin

recursive-exclude client/minicomm *
recursive-exclude * *.pyc
11 changes: 8 additions & 3 deletions accelerated/accelerated.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ PyObject *py_split_buffer(PyObject *self, PyObject *args, PyObject *kwargs) {
while (length > 0) {
Py_ssize_t decoded_length = 0;
unsigned PY_LONG_LONG tag;
int tag_type;

// Read the tag off the buffer.
varint_decode(&tag, buffer, length, &decoded_length);
Expand All @@ -168,17 +169,19 @@ PyObject *py_split_buffer(PyObject *self, PyObject *args, PyObject *kwargs) {
length -= decoded_length;

// Handle the tag depending on its type.
int tag_type = tag & TAG_TYPE_MASK;
tag_type = tag & TAG_TYPE_MASK;
switch (tag_type) {
case WIRETYPE_VARINT: {
// Decode the varint and position ourselves at the next tag.
Py_ssize_t tag_length = 0;
PyObject *entry = NULL;

varint_decode(&tag, buffer, length, &tag_length);

// Create an entry to add to the result set. Note: We use
// PyTuple_SetItem which steals the references here instead of
// PyTuple_Pack which does not (meaning its more involved to use).
PyObject *entry = PyTuple_New(3);
entry = PyTuple_New(3);
PyTuple_SET_ITEM(
entry, 0, encoded_tag);

Expand Down Expand Up @@ -257,6 +260,8 @@ PyObject *py_split_buffer(PyObject *self, PyObject *args, PyObject *kwargs) {
// data.
Py_ssize_t decoded_length = 0;
unsigned PY_LONG_LONG data_size;
PyObject *entry = NULL;

varint_decode(&data_size, buffer, length, &decoded_length);

// Check that we do not exceed the available buffer here.
Expand All @@ -267,7 +272,7 @@ PyObject *py_split_buffer(PyObject *self, PyObject *args, PyObject *kwargs) {
goto error;
}

PyObject *entry = PyTuple_New(3);
entry = PyTuple_New(3);
PyTuple_SET_ITEM(
entry, 0, encoded_tag);

Expand Down
13 changes: 0 additions & 13 deletions client/linux/requirements.txt

This file was deleted.

15 changes: 0 additions & 15 deletions client/windows/requirements.txt

This file was deleted.

15 changes: 0 additions & 15 deletions config/api_acls.yaml

This file was deleted.

3 changes: 3 additions & 0 deletions defaults.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env python
"""Autogenerated file. Do not edit."""
CONFIG_FILE = None
Binary file modified executables/windows/GRRNanny_Win32.exe
Binary file not shown.
Binary file modified executables/windows/GRRNanny_x64.exe
Binary file not shown.
File renamed without changes.
13 changes: 13 additions & 0 deletions grr/artifacts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# This directory is reserved for external artifacts

The Makefile removes ``*.yaml`` from this directory when syncing the external
repo located [here] (https://github.com/ForensicArtifacts/artifacts).

## Where artifacts go

- Private artifacts should go in ``artifacts/local``
- Public artifacts that are non GRR specific should be submitted to the external
repo.
- Public artifacts that call GRR functions with ``LIST_FILES``,
``GRR_CLIENT_ACTION``, ``GREP`` etc. should live in
``artifacts/flow_templates``
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""Test client actions."""

import __builtin__
import collections
import logging
import os
import platform
Expand Down Expand Up @@ -73,7 +74,8 @@ def cpu_percent(self):
return 10.0

def memory_info(self):
return (100000, 150000)
meminfo = collections.namedtuple("Meminfo", ["rss", "vms"])
return meminfo(rss=100000, vms=150000)

def memory_percent(self):
return 10.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ def Run(self, arg):
proc = psutil.Process(os.getpid())
meminfo = proc.memory_info()
response = rdf_client.ClientStats(
RSS_size=meminfo[0],
VMS_size=meminfo[1],
RSS_size=meminfo.rss,
VMS_size=meminfo.vms,
memory_percent=proc.memory_percent(),
bytes_received=stats.STATS.GetMetricValue(
"grr_client_received_bytes"),
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
from grr.lib.rdfvalues import client as rdf_client
from grr.lib.rdfvalues import crypto as rdf_crypto

LOADED_COMPONENTS = {}


class Site(object):
"""A copy of the relevant functions of the site Python package.
Expand Down Expand Up @@ -92,6 +94,12 @@ class LoadComponent(actions.ActionPlugin):

def LoadComponent(self, summary):
"""Import all the required modules as specified in the request."""
if (summary.name in LOADED_COMPONENTS and
summary.version != LOADED_COMPONENTS[summary.name]):
logging.error("Component %s is already loaded at version %s. Exiting!",
summary.name, LOADED_COMPONENTS[summary.name])
os._exit(0) # pylint: disable=protected-access

for mod_name in summary.modules:
logging.debug("Will import %s", mod_name)
importlib.import_module(mod_name)
Expand Down Expand Up @@ -138,6 +146,7 @@ def Run(self, request):
# Add the component path to the site packages:
site = Site()
site.AddSiteDir(component_path)
LOADED_COMPONENTS[summary.name] = summary.version

try:
self.LoadComponent(summary)
Expand Down Expand Up @@ -193,6 +202,7 @@ def Run(self, request):

# Add the component to the site packages:
site.AddSiteDir(component_path)
LOADED_COMPONENTS[component.summary.name] = component.summary.version

# If this does not work now, we just fail.
self.LoadComponent(summary)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from grr.lib import aff4
from grr.lib import config_lib
from grr.lib import flags
from grr.lib import maintenance_utils
from grr.lib import test_lib
from grr.lib.rdfvalues import client as rdf_client

Expand All @@ -40,10 +39,7 @@ class TestComponents(test_lib.EmptyActionTest):

def setUp(self):
super(TestComponents, self).setUp()
self.component = maintenance_utils.SignComponent(
os.path.join(self.base_path,
"grr-rekall_0.1_glibc_2.4_amd64_Ubuntu_Linux.bin"),
token=self.token)
self.component = test_lib.WriteComponent(token=self.token)

# The Rekall component will bring in all these new objects. Since the rekall
# component code is already loaded when the component is re-imported, Rekall
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,9 @@ def Run(self, unused_arg):
pass

try:
response.RSS_size, response.VMS_size = proc.memory_info()
pmem = proc.memory_info()
response.RSS_size = pmem.rss
response.VMS_size = pmem.vms
response.memory_percent = proc.memory_percent()
except (psutil.NoSuchProcess, psutil.AccessDenied):
pass
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,18 @@ class ErrorNotAFile(Error):
"""Attempt to delete a file that doesn't exist."""


def GetTempDirForRoot(root):
return os.path.join(root, config_lib.CONFIG["Client.grr_tempdir"])


def GetDefaultGRRTempDirectory():
# Check if any of the roots exists.
for candidate_dir in config_lib.CONFIG["Client.tempdir_roots"]:
if os.path.isdir(candidate_dir):
return os.path.join(
candidate_dir, config_lib.CONFIG["Client.grr_tempdir"])
return GetTempDirForRoot(candidate_dir)

# If none of the options exist, fall back to the first directory.
return os.path.join(
config_lib.CONFIG["Client.tempdir_roots"][0],
config_lib.CONFIG["Client.grr_tempdir"])
return GetTempDirForRoot(config_lib.CONFIG["Client.tempdir_roots"][0])


def CreateGRRTempFile(directory=None, filename=None, lifetime=0, mode="w+b",
Expand Down Expand Up @@ -197,7 +198,8 @@ def DeleteGRRTempFile(path):
raise ErrorBadPath("Path must be absolute")

prefix = config_lib.CONFIG["Client.tempfile_prefix"]
directories = config_lib.CONFIG["Client.tempdir_roots"]
directories = [GetTempDirForRoot(root)
for root in config_lib.CONFIG["Client.tempdir_roots"]]
if not _CheckIfPathIsValidForDeletion(
path, prefix=prefix, directories=directories):
msg = ("Can't delete temp file %s. Filename must start with %s "
Expand Down Expand Up @@ -234,13 +236,16 @@ def Run(self, args):
ErrorBadPath: if path doesn't exist or is not a regular file or directory
"""

# Normalize the path, so DeleteGRRTempFile can correctly check if
# it is within Client.tempdir.
allowed_temp_dirs = [GetTempDirForRoot(root)
for root in config_lib.CONFIG["Client.tempdir_roots"]]

if args.path:
# Normalize the path, so DeleteGRRTempFile can correctly check if
# it is within Client.tempdir.
paths = [client_utils.CanonicalPathToLocalPath(
utils.NormalizePath(args.path))]
else:
paths = config_lib.CONFIG["Client.tempdir_roots"]
paths = allowed_temp_dirs

deleted = []
errors = []
Expand All @@ -263,7 +268,7 @@ def Run(self, args):
DeleteGRRTempFile(path)
deleted = [path]

elif path not in config_lib.CONFIG["Client.tempdir_roots"]:
elif path not in allowed_temp_dirs:
if not os.path.exists(path):
raise ErrorBadPath("File %s does not exist" % path)
else:
Expand Down
Loading

0 comments on commit a1479d8

Please sign in to comment.