-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdlp.cpp
More file actions
67 lines (52 loc) · 1.56 KB
/
Copy pathdlp.cpp
File metadata and controls
67 lines (52 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
// Function to check if a string contains sensitive information
bool containsSensitiveInfo(const std::string &data)
{
// based on your specific requirements and policies parameters can be altered
return data.find("sensitive") != std::string::npos;
}
// Function to monitor and prevent sensitive data leaks
void monitorAndPrevent(const std::string &filename)
{
std::ifstream file(filename);
if (!file.is_open())
{
std::cerr << "Error opening file: " << filename << std::endl;
return;
}
std::vector<std::string> lines;
std::string line;
while (std::getline(file, line))
{
if (containsSensitiveInfo(line))
{
std::cerr << "Sensitive information detected: " << line << std::endl;
// Take appropriate action: log, block, alert, etc.
}
lines.push_back(line);
}
file.close();
// Optionally, you can write the modified content back to the file
std::ofstream outFile(filename);
if (!outFile.is_open())
{
std::cerr << "Error opening output file: " << filename << std::endl;
return;
}
for (const auto &l : lines)
{
outFile << l << '\n';
}
outFile.close();
}
int main()
{
// Assuming you want to monitor a file named "example.txt" you can change it to fit your file extension
std::string filename = "example.txt";
// Monitor and prevent sensitive data leaks from file or system
monitorAndPrevent(filename);
return 0;
}