mirror of
https://github.com/valitydev/osquery-1.git
synced 2024-11-06 09:35:20 +00:00
Cups Jobs and Cups Destinations (#4278)
This commit is contained in:
parent
8d16ae3887
commit
5bd021a84f
64
osquery/tables/system/darwin/cups_destinations.cpp
Normal file
64
osquery/tables/system/darwin/cups_destinations.cpp
Normal file
@ -0,0 +1,64 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under both the Apache 2.0 license (found in the
|
||||
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
||||
* in the COPYING file in the root directory of this source tree).
|
||||
* You may select, at your option, one of the above-listed licenses.
|
||||
*/
|
||||
|
||||
#include <cups/cups.h>
|
||||
|
||||
#include <osquery/tables.h>
|
||||
|
||||
namespace osquery {
|
||||
namespace tables {
|
||||
|
||||
class CupsDestinations {
|
||||
public:
|
||||
cups_dest_t* destination_list;
|
||||
int num_destinations;
|
||||
|
||||
CupsDestinations() : destination_list(nullptr), num_destinations(0) {
|
||||
num_destinations = cupsGetDests(&destination_list);
|
||||
}
|
||||
|
||||
~CupsDestinations() {
|
||||
cupsFreeDests(num_destinations, destination_list);
|
||||
}
|
||||
|
||||
cups_dest_t* begin() {
|
||||
return destination_list;
|
||||
}
|
||||
|
||||
cups_dest_t* end() {
|
||||
return &destination_list[num_destinations];
|
||||
}
|
||||
};
|
||||
|
||||
QueryData genCupsDestinations(QueryContext& request) {
|
||||
QueryData results;
|
||||
CupsDestinations dests;
|
||||
|
||||
for (const auto& dest : dests) {
|
||||
auto num_options = dest.num_options;
|
||||
if (num_options == 0) {
|
||||
Row r;
|
||||
r["name"] = SQL_TEXT(dest.name);
|
||||
results.push_back(r);
|
||||
} else {
|
||||
for (int j = 0; j < num_options; ++j) {
|
||||
Row r;
|
||||
r["name"] = SQL_TEXT(dest.name);
|
||||
r["option_name"] = SQL_TEXT(dest.options[j].name);
|
||||
r["option_value"] = SQL_TEXT(dest.options[j].value);
|
||||
results.push_back(r);
|
||||
}
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
} // namespace tables
|
||||
} // namespace osquery
|
62
osquery/tables/system/darwin/cups_jobs.cpp
Normal file
62
osquery/tables/system/darwin/cups_jobs.cpp
Normal file
@ -0,0 +1,62 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under both the Apache 2.0 license (found in the
|
||||
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
||||
* in the COPYING file in the root directory of this source tree).
|
||||
* You may select, at your option, one of the above-listed licenses.
|
||||
*/
|
||||
|
||||
#include <cups/cups.h>
|
||||
|
||||
#include <osquery/tables.h>
|
||||
|
||||
namespace osquery {
|
||||
namespace tables {
|
||||
|
||||
class CupsJobs {
|
||||
public:
|
||||
// The array given to us by the CUPS API
|
||||
cups_job_t* job_list;
|
||||
// How long the array is
|
||||
int num_jobs;
|
||||
|
||||
CupsJobs() : job_list(nullptr), num_jobs(0) {
|
||||
num_jobs = cupsGetJobs(&job_list, nullptr, 0, CUPS_WHICHJOBS_ALL);
|
||||
}
|
||||
|
||||
~CupsJobs() {
|
||||
cupsFreeJobs(num_jobs, job_list);
|
||||
}
|
||||
|
||||
cups_job_t* begin() {
|
||||
return job_list;
|
||||
}
|
||||
|
||||
cups_job_t* end() {
|
||||
return &job_list[num_jobs];
|
||||
}
|
||||
};
|
||||
|
||||
QueryData genCupsJobs(QueryContext& request) {
|
||||
QueryData results;
|
||||
CupsJobs jobs;
|
||||
|
||||
for (const auto& job : jobs) {
|
||||
Row r;
|
||||
r["title"] = SQL_TEXT(job.title);
|
||||
r["destination"] = SQL_TEXT(job.dest);
|
||||
r["user"] = SQL_TEXT(job.user);
|
||||
r["format"] = SQL_TEXT(job.format);
|
||||
r["size"] = INTEGER(job.size);
|
||||
r["completed_time"] = INTEGER(job.completed_time);
|
||||
r["processing_time"] = INTEGER(job.processing_time);
|
||||
r["creation_time"] = INTEGER(job.creation_time);
|
||||
results.push_back(r);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
} // namespace tables
|
||||
} // namespace osquery
|
8
specs/darwin/cups_destinations.table
Normal file
8
specs/darwin/cups_destinations.table
Normal file
@ -0,0 +1,8 @@
|
||||
table_name("cups_destinations")
|
||||
description("Returns all configured printers.")
|
||||
schema([
|
||||
Column("name", TEXT, "Name of the printer"),
|
||||
Column("option_name", TEXT, "Option name"),
|
||||
Column("option_value", TEXT, "Option value")
|
||||
])
|
||||
implementation("cups_destinations@genCupsDestinations")
|
13
specs/darwin/cups_jobs.table
Normal file
13
specs/darwin/cups_jobs.table
Normal file
@ -0,0 +1,13 @@
|
||||
table_name("cups_jobs")
|
||||
description("Returns all completed print jobs from cups.")
|
||||
schema([
|
||||
Column("title", TEXT, "Title of the printed job"),
|
||||
Column("destination", TEXT, "The printer the job was sent to"),
|
||||
Column("user", TEXT, "The user who printed the job"),
|
||||
Column("format", TEXT, "The format of the print job"),
|
||||
Column("size", INTEGER, "The size of the print job"),
|
||||
Column("completed_time", INTEGER, "When the job completed printing"),
|
||||
Column("processing_time", INTEGER, "How long the job took to process"),
|
||||
Column("creation_time", INTEGER, "When the print request was initiated"),
|
||||
])
|
||||
implementation("cups_jobs@genCupsJobs")
|
Loading…
Reference in New Issue
Block a user