for (auto entry : testfiles) {
struct stat st;
std::string logStr(entry + " change");
- lstat(entry.c_str(), &st);
- chmod(entry.c_str(), st.st_mode);
- Display::printResult(Display::SUCCESS, logStr);
+
+ if (lstat(entry.c_str(), &st) == 0) {
+ if (chmod(entry.c_str(), st.st_mode) == 0)
+ Display::printResult(Display::SUCCESS, logStr);
+ else
+ Display::printResult(Display::FAIL, logStr);
+ } else {
+ Display::printResult(Display::FAIL, logStr);
+ }
}
}
//restore
{
- struct stat st;
- if ((lstat(fileName.c_str(), &st) == 0) && (unlink(fileName.c_str()) != 0)) {
+ if (unlink(fileName.c_str()) != 0) {
Display::printError();
Display::printResult(Display::FAIL, "accessFile restore");
}
//restore
{
- struct stat st;
- if ((lstat(fileName.c_str(), &st) == 0) && (unlink(fileName.c_str()) != 0)) {
+ if (unlink(fileName.c_str()) != 0) {
Display::printError();
Display::printResult(Display::FAIL, "destroyFile restore");
}
//restore
{
- struct stat st;
if (fd >= 0)
close(fd);
- if ((lstat(fileName.c_str(), &st) == 0) && (unlink(fileName.c_str()) != 0)) {
+ if (unlink(fileName.c_str()) != 0) {
Display::printError();
Display::printResult(Display::FAIL, "createLink restore");
}
//restore
{
- struct stat st;
- if ((lstat(fileName.c_str(), &st) == 0) && (unlink(fileName.c_str()) != 0)) {
+ if (unlink(fileName.c_str()) != 0) {
Display::printError();
Display::printResult(Display::FAIL, "changeFileConf restore");
}
//restore
{
- struct stat st;
- if ((lstat(fileName.c_str(), &st) == 0) && (unlink(fileName.c_str()) != 0)) {
+ if (unlink(fileName.c_str()) != 0) {
Display::printError();
Display::printResult(Display::FAIL, "changeFileConfMAC restore");
}
}
msgctl_result:
- struct stat st;
- if (lstat(msgKeyPath.c_str(), &st) == 0)
- rmdir(msgKeyPath.c_str());
+ if (rmdir(msgKeyPath.c_str()) != 0)
+ Display::printError();
+
Display::printResult(ret, "msgctl(303) positive");
}
int recvlen = 0;
int backlog = 10;
struct sockaddr_un addr;
- struct stat st;
std::thread client;
if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX;
strncpy(addr.sun_path, sockaddr.c_str(), sizeof(sockaddr_un::sun_path));
+ addr.sun_path[sizeof(sockaddr_un::sun_path) - 1] = '\0';
if (bind(fd, reinterpret_cast<struct sockaddr *>(&addr), sizeof(struct sockaddr_un)) == -1) {
close(fd);
memset(&serveraddr, 0, sizeof(serveraddr));
serveraddr.sun_family = AF_UNIX;
strncpy(serveraddr.sun_path, sockaddr.c_str(), sizeof(sockaddr_un::sun_path));
+ serveraddr.sun_path[sizeof(sockaddr_un::sun_path) - 1] = '\0';
if (connect(clientFd, reinterpret_cast<struct sockaddr *>(&serveraddr), sizeof(serveraddr)) == -1) {
close(clientFd);
Display::printError();
return;
}
- send(clientFd, message.c_str(), message.size(), 0);
+
+ if (send(clientFd, message.c_str(), message.size(), 0) < 0) {
+ Display::printError();
+ Display::printResult(Display::FAIL, "useSocket positive");
+ }
if (clientFd >= 0)
close(clientFd);
return;
}
memset(buffer, 0, sizeof(buffer));
-
if((recvlen = recv(cliFd, buffer, sizeof(buffer), 0)) == -1)
Display::printError();
if (recvlen > 0) {
+ buffer[recvlen] = '\0';
Display::printResult(Display::NONE, std::string(buffer));
Display::printResult(Display::SUCCESS, "useSocket positive");
} else {
close(cliFd);
if (fd >= 0)
close(fd);
- if ((lstat(sockaddr.c_str(), &st) == 0) && (unlink(sockaddr.c_str()) != 0))
+
+
+ if (unlink(sockaddr.c_str()) != 0)
Display::printError();
}
};
for (auto entry : paths) {
struct stat st;
std::string logStr(entry + " change");
- lstat(entry.c_str(), &st);
- chmod(entry.c_str(), st.st_mode);
- Display::printResult(Display::SUCCESS, logStr);
+ if (lstat(entry.c_str(), &st) == 0) {
+ if (chmod(entry.c_str(), st.st_mode) == 0)
+ Display::printResult(Display::SUCCESS, logStr);
+ else
+ Display::printResult(Display::FAIL, logStr);
+ } else {
+ Display::printResult(Display::FAIL, logStr);
+ }
}
}
for (auto entry : testPath) {
struct stat st;
std::string logStr(entry + " access");
- lstat(entry.c_str(), &st);
- chmod(entry.c_str(), st.st_mode);
- Display::printResult(Display::SUCCESS, logStr);
+
+ if (lstat(entry.c_str(), &st) == 0) {
+ if (chmod(entry.c_str(), st.st_mode) == 0)
+ Display::printResult(Display::SUCCESS, logStr);
+ else
+ Display::printResult(Display::FAIL, logStr);
+ } else {
+ Display::printResult(Display::FAIL, logStr);
+ }
}
}
}
for (std::string entry : mountPath) {
- struct stat st;
- if ((lstat(entry.c_str(), &st) == 0) && (rmdir(entry.c_str()) != 0))
+ if (rmdir(entry.c_str()) != 0)
Display::printError();
}
}
std::string testPath("/etc/ld.so.conf");
struct stat st;
- lstat(testPath.c_str(), &st);
- chmod(testPath.c_str(), st.st_mode);
- Display::printResult(Display::SUCCESS, "change /etc/ld.so.conf");
+ if (lstat(testPath.c_str(), &st) == 0) {
+ if (chmod(testPath.c_str(), st.st_mode) == 0)
+ Display::printResult(Display::SUCCESS, "change /etc/ld.so.conf");
+ else
+ Display::printResult(Display::FAIL, "change /etc/ld.so.conf");
+ } else {
+ Display::printError();
+ Display::printResult(Display::FAIL, "change /etc/ld.so.conf");
+ }
}
void changeKernelModule() {
std::string testPath("/etc/modules-load.d");
struct stat st;
- lstat(testPath.c_str(), &st);
- chmod(testPath.c_str(), st.st_mode);
- Display::printResult(Display::SUCCESS, "change /etc/modules-load.d");
+ if (lstat(testPath.c_str(), &st) == 0) {
+ if (chmod(testPath.c_str(), st.st_mode) == 0)
+ Display::printResult(Display::SUCCESS, "change /etc/modules-load.d");
+ else
+ Display::printResult(Display::FAIL, "change /etc/modules-load.d");
+ } else {
+ Display::printError();
+ Display::printResult(Display::FAIL, "change /etc/modules-load.d");
+ }
}
void useKernelModule() {
for (auto entry : testPath) {
std::string logStr(entry + " access");
- lstat(entry.c_str(), &st);
- chmod(entry.c_str(), st.st_mode);
- Display::printResult(Display::SUCCESS, logStr);
+ if (lstat(entry.c_str(), &st) == 0) {
+ if (chmod(entry.c_str(), st.st_mode) == 0)
+ Display::printResult(Display::SUCCESS, logStr);
+ else
+ Display::printResult(Display::FAIL, logStr);
+ } else {
+ Display::printResult(Display::FAIL, logStr);
+ }
}
}