<commit_before>// Copyright 2004-present Facebook. All Rights Reserved.

#include <string>
#include <vector>

#include <pwd.h>

#include <boost/lexical_cast.hpp>

#include <glog/logging.h>

#include "osquery/core.h"
#include "osquery/database.h"
#include "osquery/filesystem.h"
#include "osquery/sql.h"

namespace osquery {
namespace tables {

const std::vector<std::string> kShellHistoryFiles = {
  ".bash_history", ".zsh_history", ".zhistory", ".history",
};

QueryData genBashHistory() {
  QueryData results;
  std::string sql_str;

  if (!getuid()) {
    sql_str = "SELECT username,directory FROM users";
  } else {
    struct passwd *pwd = nullptr;
    pwd = getpwuid(getuid());
    // TODO: Come back here when osquery supports parametrized queries, until then SQLi!
    sql_str = "SELECT username,directory FROM users WHERE username = '" + std::string(pwd->pw_name) + "';";
  }

  auto sql = SQL(sql_str);

  if (!sql.ok()) {
    LOG(ERROR) << "Error executing SQL: " << sql.getMessageString();
    return results;
  }<commit_msg>updating comment<commit_after>// Copyright 2004-present Facebook. All Rights Reserved.

#include <string>
#include <vector>

#include <pwd.h>

#include <boost/lexical_cast.hpp>

#include <glog/logging.h>

#include "osquery/core.h"
#include "osquery/database.h"
#include "osquery/filesystem.h"
#include "osquery/sql.h"

namespace osquery {
namespace tables {

const std::vector<std::string> kShellHistoryFiles = {
  ".bash_history", ".zsh_history", ".zhistory", ".history",
};

QueryData genBashHistory() {
  QueryData results;
  std::string sql_str;

  if (!getuid()) {
    sql_str = "SELECT username,directory FROM users";
  } else {
    struct passwd *pwd = nullptr;
    pwd = getpwuid(getuid());
    // TODO: https://github.com/facebook/osquery/issues/244
    sql_str = "SELECT username,directory FROM users WHERE username = '" + std::string(pwd->pw_name) + "';";
  }

  auto sql = SQL(sql_str);

  if (!sql.ok()) {
    LOG(ERROR) << "Error executing SQL: " << sql.getMessageString();
    return results;
  }
{'fraction_non_alphanumeric': 0.1552734375, 'fraction_numerical': 0.00537109375, 'mean_word_length': 4.213740458015267, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 17, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5201843', 'n_tokens_mistral': 707, 'n_tokens_neox': 685, 'n_words': 167}