From bc91a4848c6696f4e54a58104196f3c64e6760fd Mon Sep 17 00:00:00 2001 From: Aleksander Zdyb Date: Fri, 19 Jun 2015 11:38:16 +0200 Subject: [PATCH] Add objective wrappers for libaudit functions The wrapper is needed to make unit testing possible. Change-Id: Ic3ca40e04d11d9151b8c0a8e358a4697a641cd22 --- src/Audit/AuditWrapper.cpp | 81 ++++++++++++++++++++++++++++++++++++++++++++ src/Audit/AuditWrapper.h | 54 +++++++++++++++++++++++++++++ src/Audit/BaseAuditWrapper.h | 54 +++++++++++++++++++++++++++++ 3 files changed, 189 insertions(+) create mode 100644 src/Audit/AuditWrapper.cpp create mode 100644 src/Audit/AuditWrapper.h create mode 100644 src/Audit/BaseAuditWrapper.h diff --git a/src/Audit/AuditWrapper.cpp b/src/Audit/AuditWrapper.cpp new file mode 100644 index 0000000..36711dc --- /dev/null +++ b/src/Audit/AuditWrapper.cpp @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @file src/Audit/AuditWrapper.cpp + * @author Aleksander Zdyb + * @version 1.0 + */ + + #include + +#include +extern int _audit_syscalladded; // God bless them + +#include "AuditWrapper.h" + +namespace Audit { + +int AuditWrapper::audit_open(void) { + return ::audit_open(); +} + +void AuditWrapper::audit_close(int fd) { + ::audit_close(fd); +} + +int AuditWrapper::audit_add_rule_data(int fd, struct audit_rule_data *rule, int flags, int action) { + return ::audit_add_rule_data(fd, rule, flags, action); +} + +int AuditWrapper::audit_delete_rule_data(int fd, struct audit_rule_data *rule, int flags, + int action) +{ + return ::audit_delete_rule_data(fd, rule, flags, action); +} + +int AuditWrapper::audit_rule_syscallbyname_data(struct audit_rule_data *rule, const char *scall) { + auto ret = ::audit_rule_syscallbyname_data(rule, scall); + if (ret == 0) + _audit_syscalladded = 1; + return ret; +} + +int AuditWrapper::audit_rule_fieldpair_data(struct audit_rule_data **rulep, const char *pair, + int flags) { + return ::audit_rule_fieldpair_data(rulep, pair, flags); +} + +void AuditWrapper::audit_rule_free_data(struct audit_rule_data *rule) { + ::audit_rule_free_data(rule); +} + +audit_rule_data *AuditWrapper::create_rule_data() { + return static_cast(calloc(1, sizeof(struct audit_rule_data))); +} + +int AuditWrapper::MAX_AUDIT_MESSAGE_LENGTH_CONST() const { + return MAX_AUDIT_MESSAGE_LENGTH; +} + +int AuditWrapper::AUDIT_FILTER_EXIT_CONST() const { + return AUDIT_FILTER_EXIT; +} + +int AuditWrapper::AUDIT_ALWAYS_CONST() const { + return AUDIT_ALWAYS; +} + +} /* namespace Audit */ diff --git a/src/Audit/AuditWrapper.h b/src/Audit/AuditWrapper.h new file mode 100644 index 0000000..3701e61 --- /dev/null +++ b/src/Audit/AuditWrapper.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @file src/Audit/AuditWrapper.h + * @author Aleksander Zdyb + * @version 1.0 + */ + +#ifndef SRC_AUDIT_AUDITWRAPPER_H +#define SRC_AUDIT_AUDITWRAPPER_H + +#include "BaseAuditWrapper.h" + +namespace Audit { + +class AuditWrapper : public BaseAuditWrapper { +public: + using BaseAuditWrapper::BaseAuditWrapper; + virtual ~AuditWrapper() = default; + + virtual int audit_open(void); + virtual void audit_close(int fd); + + virtual int audit_add_rule_data(int fd, struct audit_rule_data *rule, int flags, int action); + virtual int audit_delete_rule_data(int fd, struct audit_rule_data *rule, int flags, + int action); + virtual int audit_rule_syscallbyname_data(struct audit_rule_data *rule, const char *scall); + virtual int audit_rule_fieldpair_data(struct audit_rule_data **rulep, const char *pair, + int flags); + virtual void audit_rule_free_data(struct audit_rule_data *rule); + + virtual audit_rule_data *create_rule_data(); + + virtual int MAX_AUDIT_MESSAGE_LENGTH_CONST() const; + virtual int AUDIT_FILTER_EXIT_CONST() const; + virtual int AUDIT_ALWAYS_CONST() const; +}; + +} /* namespace Audit */ + +#endif /* SRC_AUDIT_AUDITWRAPPER_H */ diff --git a/src/Audit/BaseAuditWrapper.h b/src/Audit/BaseAuditWrapper.h new file mode 100644 index 0000000..bdccee7 --- /dev/null +++ b/src/Audit/BaseAuditWrapper.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @file src/Audit/BaseAuditWrapper.h + * @author Aleksander Zdyb + * @version 1.0 + */ + +#ifndef SRC_AUDIT_BASEAUDITWRAPPER_H +#define SRC_AUDIT_BASEAUDITWRAPPER_H + +struct audit_rule_data; + +namespace Audit { + +class BaseAuditWrapper { +public: + virtual ~BaseAuditWrapper() = default; + + virtual int audit_open(void) = 0; + virtual void audit_close(int fd) = 0; + + virtual int audit_add_rule_data(int fd, struct audit_rule_data *rule, int flags, + int action) = 0; + virtual int audit_delete_rule_data(int fd, struct audit_rule_data *rule, int flags, + int action) = 0; + virtual int audit_rule_syscallbyname_data(struct audit_rule_data *rule, const char *scall) = 0; + virtual int audit_rule_fieldpair_data(struct audit_rule_data **rulep, const char *pair, + int flags) = 0; + virtual void audit_rule_free_data(struct audit_rule_data *rule) = 0; + + virtual struct audit_rule_data *create_rule_data() = 0; + + virtual int MAX_AUDIT_MESSAGE_LENGTH_CONST() const = 0; + virtual int AUDIT_FILTER_EXIT_CONST() const = 0; + virtual int AUDIT_ALWAYS_CONST() const = 0; +}; + +} /* namespace Audit */ + +#endif /* SRC_AUDIT_BASEAUDITWRAPPER_H */ -- 2.7.4