Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame^] | 16 | #include "Log.h" |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 17 | |
| 18 | #include "IncidentService.h" |
| 19 | |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame^] | 20 | #include "FdBuffer.h" |
| 21 | #include "PrivacyBuffer.h" |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 22 | #include "Reporter.h" |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame^] | 23 | #include "incidentd_util.h" |
| 24 | #include "section_list.h" |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 25 | |
| 26 | #include <binder/IPCThreadState.h> |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame^] | 27 | #include <binder/IResultReceiver.h> |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 28 | #include <binder/IServiceManager.h> |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame^] | 29 | #include <binder/IShellCallback.h> |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 30 | #include <cutils/log.h> |
| 31 | #include <private/android_filesystem_config.h> |
| 32 | #include <utils/Looper.h> |
| 33 | |
| 34 | #include <unistd.h> |
| 35 | |
| 36 | using namespace android; |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame^] | 37 | using namespace android::base; |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 38 | |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame^] | 39 | enum { WHAT_RUN_REPORT = 1, WHAT_SEND_BACKLOG_TO_DROPBOX = 2 }; |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 40 | |
| 41 | //#define DEFAULT_BACKLOG_DELAY_NS (1000000000LL * 60 * 5) |
| 42 | #define DEFAULT_BACKLOG_DELAY_NS (1000000000LL) |
| 43 | |
| 44 | // ================================================================================ |
| 45 | String16 const DUMP_PERMISSION("android.permission.DUMP"); |
| 46 | String16 const USAGE_STATS_PERMISSION("android.permission.PACKAGE_USAGE_STATS"); |
| 47 | |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame^] | 48 | static Status checkIncidentPermissions(const IncidentReportArgs& args) { |
Yi Jin | 437aa6e | 2018-01-10 11:34:26 -0800 | [diff] [blame] | 49 | uid_t callingUid = IPCThreadState::self()->getCallingUid(); |
Yi Jin | afb3606 | 2018-01-31 19:14:25 -0800 | [diff] [blame] | 50 | pid_t callingPid = IPCThreadState::self()->getCallingPid(); |
Yi Jin | 437aa6e | 2018-01-10 11:34:26 -0800 | [diff] [blame] | 51 | if (callingUid == AID_ROOT || callingUid == AID_SHELL) { |
| 52 | // root doesn't have permission.DUMP if don't do this! |
| 53 | return Status::ok(); |
| 54 | } |
| 55 | |
Yi Jin | 4bab3a1 | 2018-01-10 16:50:59 -0800 | [diff] [blame] | 56 | // checking calling permission. |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 57 | if (!checkCallingPermission(DUMP_PERMISSION)) { |
| 58 | ALOGW("Calling pid %d and uid %d does not have permission: android.permission.DUMP", |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame^] | 59 | callingPid, callingUid); |
| 60 | return Status::fromExceptionCode( |
| 61 | Status::EX_SECURITY, |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 62 | "Calling process does not have permission: android.permission.DUMP"); |
| 63 | } |
| 64 | if (!checkCallingPermission(USAGE_STATS_PERMISSION)) { |
| 65 | ALOGW("Calling pid %d and uid %d does not have permission: android.permission.USAGE_STATS", |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame^] | 66 | callingPid, callingUid); |
| 67 | return Status::fromExceptionCode( |
| 68 | Status::EX_SECURITY, |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 69 | "Calling process does not have permission: android.permission.USAGE_STATS"); |
| 70 | } |
Yi Jin | 4bab3a1 | 2018-01-10 16:50:59 -0800 | [diff] [blame] | 71 | |
| 72 | // checking calling request uid permission. |
Yi Jin | 4bab3a1 | 2018-01-10 16:50:59 -0800 | [diff] [blame] | 73 | switch (args.dest()) { |
| 74 | case DEST_LOCAL: |
Yi Jin | afb3606 | 2018-01-31 19:14:25 -0800 | [diff] [blame] | 75 | if (callingUid != AID_SHELL && callingUid != AID_ROOT) { |
| 76 | ALOGW("Calling pid %d and uid %d does not have permission to get local data.", |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame^] | 77 | callingPid, callingUid); |
| 78 | return Status::fromExceptionCode( |
| 79 | Status::EX_SECURITY, |
| 80 | "Calling process does not have permission to get local data."); |
Yi Jin | 4bab3a1 | 2018-01-10 16:50:59 -0800 | [diff] [blame] | 81 | } |
| 82 | case DEST_EXPLICIT: |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame^] | 83 | if (callingUid != AID_SHELL && callingUid != AID_ROOT && callingUid != AID_STATSD && |
| 84 | callingUid != AID_SYSTEM) { |
Yi Jin | afb3606 | 2018-01-31 19:14:25 -0800 | [diff] [blame] | 85 | ALOGW("Calling pid %d and uid %d does not have permission to get explicit data.", |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame^] | 86 | callingPid, callingUid); |
| 87 | return Status::fromExceptionCode( |
| 88 | Status::EX_SECURITY, |
| 89 | "Calling process does not have permission to get explicit data."); |
Yi Jin | 4bab3a1 | 2018-01-10 16:50:59 -0800 | [diff] [blame] | 90 | } |
| 91 | } |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 92 | return Status::ok(); |
| 93 | } |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 94 | // ================================================================================ |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame^] | 95 | ReportRequestQueue::ReportRequestQueue() {} |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 96 | |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame^] | 97 | ReportRequestQueue::~ReportRequestQueue() {} |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 98 | |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame^] | 99 | void ReportRequestQueue::addRequest(const sp<ReportRequest>& request) { |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 100 | unique_lock<mutex> lock(mLock); |
| 101 | mQueue.push_back(request); |
| 102 | } |
| 103 | |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame^] | 104 | sp<ReportRequest> ReportRequestQueue::getNextRequest() { |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 105 | unique_lock<mutex> lock(mLock); |
| 106 | if (mQueue.empty()) { |
| 107 | return NULL; |
| 108 | } else { |
| 109 | sp<ReportRequest> front(mQueue.front()); |
| 110 | mQueue.pop_front(); |
| 111 | return front; |
| 112 | } |
| 113 | } |
| 114 | |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 115 | // ================================================================================ |
| 116 | ReportHandler::ReportHandler(const sp<Looper>& handlerLooper, const sp<ReportRequestQueue>& queue) |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame^] | 117 | : mBacklogDelay(DEFAULT_BACKLOG_DELAY_NS), mHandlerLooper(handlerLooper), mQueue(queue) {} |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 118 | |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame^] | 119 | ReportHandler::~ReportHandler() {} |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 120 | |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame^] | 121 | void ReportHandler::handleMessage(const Message& message) { |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 122 | switch (message.what) { |
| 123 | case WHAT_RUN_REPORT: |
| 124 | run_report(); |
| 125 | break; |
| 126 | case WHAT_SEND_BACKLOG_TO_DROPBOX: |
| 127 | send_backlog_to_dropbox(); |
| 128 | break; |
| 129 | } |
| 130 | } |
| 131 | |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame^] | 132 | void ReportHandler::scheduleRunReport(const sp<ReportRequest>& request) { |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 133 | mQueue->addRequest(request); |
| 134 | mHandlerLooper->removeMessages(this, WHAT_RUN_REPORT); |
| 135 | mHandlerLooper->sendMessage(this, Message(WHAT_RUN_REPORT)); |
| 136 | } |
| 137 | |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame^] | 138 | void ReportHandler::scheduleSendBacklogToDropbox() { |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 139 | unique_lock<mutex> lock(mLock); |
| 140 | mBacklogDelay = DEFAULT_BACKLOG_DELAY_NS; |
| 141 | schedule_send_backlog_to_dropbox_locked(); |
| 142 | } |
| 143 | |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame^] | 144 | void ReportHandler::schedule_send_backlog_to_dropbox_locked() { |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 145 | mHandlerLooper->removeMessages(this, WHAT_SEND_BACKLOG_TO_DROPBOX); |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame^] | 146 | mHandlerLooper->sendMessageDelayed(mBacklogDelay, this, Message(WHAT_SEND_BACKLOG_TO_DROPBOX)); |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 147 | } |
| 148 | |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame^] | 149 | void ReportHandler::run_report() { |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 150 | sp<Reporter> reporter = new Reporter(); |
| 151 | |
| 152 | // Merge all of the requests into one that has all of the |
| 153 | // requested fields. |
| 154 | while (true) { |
| 155 | sp<ReportRequest> request = mQueue->getNextRequest(); |
| 156 | if (request == NULL) { |
| 157 | break; |
| 158 | } |
| 159 | reporter->batch.add(request); |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | // Take the report, which might take a while. More requests might queue |
| 163 | // up while we're doing this, and we'll handle them in their next batch. |
| 164 | // TODO: We should further rate-limit the reports to no more than N per time-period. |
| 165 | Reporter::run_report_status_t reportStatus = reporter->runReport(); |
| 166 | if (reportStatus == Reporter::REPORT_NEEDS_DROPBOX) { |
| 167 | unique_lock<mutex> lock(mLock); |
| 168 | schedule_send_backlog_to_dropbox_locked(); |
| 169 | } |
| 170 | } |
| 171 | |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame^] | 172 | void ReportHandler::send_backlog_to_dropbox() { |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 173 | if (Reporter::upload_backlog() == Reporter::REPORT_NEEDS_DROPBOX) { |
| 174 | // There was a failure. Exponential backoff. |
| 175 | unique_lock<mutex> lock(mLock); |
| 176 | mBacklogDelay *= 2; |
| 177 | ALOGI("Error sending to dropbox. Trying again in %lld minutes", |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame^] | 178 | (mBacklogDelay / (1000000000LL * 60))); |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 179 | schedule_send_backlog_to_dropbox_locked(); |
| 180 | } else { |
| 181 | mBacklogDelay = DEFAULT_BACKLOG_DELAY_NS; |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | // ================================================================================ |
| 186 | IncidentService::IncidentService(const sp<Looper>& handlerLooper) |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame^] | 187 | : mQueue(new ReportRequestQueue()) { |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 188 | mHandler = new ReportHandler(handlerLooper, mQueue); |
| 189 | } |
| 190 | |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame^] | 191 | IncidentService::~IncidentService() {} |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 192 | |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame^] | 193 | Status IncidentService::reportIncident(const IncidentReportArgs& args) { |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 194 | ALOGI("reportIncident"); |
| 195 | |
Yi Jin | 4bab3a1 | 2018-01-10 16:50:59 -0800 | [diff] [blame] | 196 | Status status = checkIncidentPermissions(args); |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 197 | if (!status.isOk()) { |
| 198 | return status; |
| 199 | } |
| 200 | |
| 201 | mHandler->scheduleRunReport(new ReportRequest(args, NULL, -1)); |
| 202 | |
| 203 | return Status::ok(); |
| 204 | } |
| 205 | |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame^] | 206 | Status IncidentService::reportIncidentToStream(const IncidentReportArgs& args, |
| 207 | const sp<IIncidentReportStatusListener>& listener, |
| 208 | const unique_fd& stream) { |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 209 | ALOGI("reportIncidentToStream"); |
| 210 | |
Yi Jin | 4bab3a1 | 2018-01-10 16:50:59 -0800 | [diff] [blame] | 211 | Status status = checkIncidentPermissions(args); |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 212 | if (!status.isOk()) { |
| 213 | return status; |
| 214 | } |
| 215 | |
| 216 | int fd = dup(stream.get()); |
| 217 | if (fd < 0) { |
| 218 | return Status::fromStatusT(-errno); |
| 219 | } |
| 220 | |
| 221 | mHandler->scheduleRunReport(new ReportRequest(args, listener, fd)); |
| 222 | |
| 223 | return Status::ok(); |
| 224 | } |
| 225 | |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame^] | 226 | Status IncidentService::systemRunning() { |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 227 | if (IPCThreadState::self()->getCallingUid() != AID_SYSTEM) { |
| 228 | return Status::fromExceptionCode(Status::EX_SECURITY, |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame^] | 229 | "Only system uid can call systemRunning"); |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 230 | } |
Yi Jin | add11e9 | 2017-07-30 16:10:07 -0700 | [diff] [blame] | 231 | |
Joe Onorato | 1754d74 | 2016-11-21 17:51:35 -0800 | [diff] [blame] | 232 | // When system_server is up and running, schedule the dropbox task to run. |
| 233 | mHandler->scheduleSendBacklogToDropbox(); |
| 234 | |
| 235 | return Status::ok(); |
| 236 | } |
| 237 | |
Yi Jin | b592e3b | 2018-02-01 15:17:04 -0800 | [diff] [blame^] | 238 | /** |
| 239 | * Implement our own because the default binder implementation isn't |
| 240 | * properly handling SHELL_COMMAND_TRANSACTION. |
| 241 | */ |
| 242 | status_t IncidentService::onTransact(uint32_t code, const Parcel& data, Parcel* reply, |
| 243 | uint32_t flags) { |
| 244 | status_t err; |
| 245 | |
| 246 | switch (code) { |
| 247 | case SHELL_COMMAND_TRANSACTION: { |
| 248 | int in = data.readFileDescriptor(); |
| 249 | int out = data.readFileDescriptor(); |
| 250 | int err = data.readFileDescriptor(); |
| 251 | int argc = data.readInt32(); |
| 252 | Vector<String8> args; |
| 253 | for (int i = 0; i < argc && data.dataAvail() > 0; i++) { |
| 254 | args.add(String8(data.readString16())); |
| 255 | } |
| 256 | sp<IShellCallback> shellCallback = IShellCallback::asInterface(data.readStrongBinder()); |
| 257 | sp<IResultReceiver> resultReceiver = |
| 258 | IResultReceiver::asInterface(data.readStrongBinder()); |
| 259 | |
| 260 | FILE* fin = fdopen(in, "r"); |
| 261 | FILE* fout = fdopen(out, "w"); |
| 262 | FILE* ferr = fdopen(err, "w"); |
| 263 | |
| 264 | if (fin == NULL || fout == NULL || ferr == NULL) { |
| 265 | resultReceiver->send(NO_MEMORY); |
| 266 | } else { |
| 267 | err = command(fin, fout, ferr, args); |
| 268 | resultReceiver->send(err); |
| 269 | } |
| 270 | |
| 271 | if (fin != NULL) { |
| 272 | fflush(fin); |
| 273 | fclose(fin); |
| 274 | } |
| 275 | if (fout != NULL) { |
| 276 | fflush(fout); |
| 277 | fclose(fout); |
| 278 | } |
| 279 | if (fout != NULL) { |
| 280 | fflush(ferr); |
| 281 | fclose(ferr); |
| 282 | } |
| 283 | |
| 284 | return NO_ERROR; |
| 285 | } |
| 286 | default: { return BnIncidentManager::onTransact(code, data, reply, flags); } |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | status_t IncidentService::command(FILE* in, FILE* out, FILE* err, Vector<String8>& args) { |
| 291 | const int argCount = args.size(); |
| 292 | |
| 293 | if (argCount >= 1) { |
| 294 | if (!args[0].compare(String8("privacy"))) { |
| 295 | return cmd_privacy(in, out, err, args); |
| 296 | } |
| 297 | } |
| 298 | return cmd_help(out); |
| 299 | } |
| 300 | |
| 301 | status_t IncidentService::cmd_help(FILE* out) { |
| 302 | fprintf(out, "usage: adb shell cmd incident privacy print <section_id>\n"); |
| 303 | fprintf(out, "usage: adb shell cmd incident privacy parse <section_id> < proto.txt\n"); |
| 304 | fprintf(out, " Prints/parses for the section id.\n"); |
| 305 | return NO_ERROR; |
| 306 | } |
| 307 | |
| 308 | static void printPrivacy(const Privacy* p, FILE* out, String8 indent) { |
| 309 | if (p == NULL) return; |
| 310 | fprintf(out, "%sid:%d, type:%d, dest:%d\n", indent.string(), p->field_id, p->type, p->dest); |
| 311 | if (p->children == NULL) return; |
| 312 | for (int i = 0; p->children[i] != NULL; i++) { // NULL-terminated. |
| 313 | printPrivacy(p->children[i], out, indent + " "); |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | status_t IncidentService::cmd_privacy(FILE* in, FILE* out, FILE* err, Vector<String8>& args) { |
| 318 | const int argCount = args.size(); |
| 319 | if (argCount >= 3) { |
| 320 | String8 opt = args[1]; |
| 321 | int sectionId = atoi(args[2].string()); |
| 322 | |
| 323 | const Privacy* p = get_privacy_of_section(sectionId); |
| 324 | if (p == NULL) { |
| 325 | fprintf(err, "Can't find section id %d\n", sectionId); |
| 326 | return NO_ERROR; |
| 327 | } |
| 328 | fprintf(err, "Get privacy for %d\n", sectionId); |
| 329 | if (opt == "print") { |
| 330 | printPrivacy(p, out, String8("")); |
| 331 | } else if (opt == "parse") { |
| 332 | FdBuffer buf; |
| 333 | status_t error = buf.read(fileno(in), 60000); |
| 334 | if (error != NO_ERROR) { |
| 335 | fprintf(err, "Error reading from stdin\n"); |
| 336 | return error; |
| 337 | } |
| 338 | fprintf(err, "Read %zu bytes\n", buf.size()); |
| 339 | auto data = buf.data(); |
| 340 | PrivacyBuffer pBuf(p, data); |
| 341 | |
| 342 | PrivacySpec spec = PrivacySpec::new_spec(argCount > 3 ? atoi(args[3]) : -1); |
| 343 | error = pBuf.strip(spec); |
| 344 | if (error != NO_ERROR) { |
| 345 | fprintf(err, "Error strip pii fields with spec %d\n", spec.dest); |
| 346 | return error; |
| 347 | } |
| 348 | return pBuf.flush(fileno(out)); |
| 349 | } |
| 350 | } else { |
| 351 | return cmd_help(out); |
| 352 | } |
| 353 | return NO_ERROR; |
| 354 | } |