Skip to content

Commit 9de809a

Browse files
committed
audit: fix audit-num default value issue.
1 parent bc470ba commit 9de809a

File tree

2 files changed

+81
-1
lines changed

2 files changed

+81
-1
lines changed

src/dns_conf/dns_conf.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,11 @@ static void _dns_conf_default_value_init(void)
356356
dns_conf.cache_checkpoint_time = DNS_DEFAULT_CHECKPOINT_TIME;
357357
dns_conf.cache_persist = 2;
358358
dns_conf.log_num = 8;
359-
dns_conf.log_size = 1024 * 1024;
359+
dns_conf.log_size = 1024 * 128;
360360
dns_conf.log_level = TLOG_ERROR;
361+
dns_conf.audit_num = 2;
362+
dns_conf.audit_file_mode = 0640;
363+
dns_conf.audit_size = 1024 * 128;
361364
dns_conf.resolv_hostname = 1;
362365
dns_conf.cachesize = -1;
363366
dns_conf.cache_max_memsize = -1;

test/cases/test-audit.cc

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*************************************************************************
2+
*
3+
* Copyright (C) 2018-2025 Ruilin Peng (Nick) <[email protected]>.
4+
*
5+
* smartdns is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* smartdns is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
#include "client.h"
20+
#include "include/utils.h"
21+
#include "server.h"
22+
#include "smartdns/dns.h"
23+
#include "gtest/gtest.h"
24+
25+
class Audit : public ::testing::Test
26+
{
27+
protected:
28+
virtual void SetUp() {}
29+
virtual void TearDown() {}
30+
};
31+
32+
TEST_F(Audit, log)
33+
{
34+
smartdns::MockServer server_upstream;
35+
smartdns::Server server;
36+
37+
Defer
38+
{
39+
unlink("/tmp/audit.log");
40+
};
41+
42+
server_upstream.Start("udp://0.0.0.0:61053", [](struct smartdns::ServerRequestContext *request) {
43+
if (request->qtype != DNS_T_A) {
44+
return smartdns::SERVER_REQUEST_SOA;
45+
}
46+
47+
smartdns::MockServer::AddIP(request, request->domain.c_str(), "1.2.3.4", 611);
48+
return smartdns::SERVER_REQUEST_OK;
49+
});
50+
51+
server.Start(R"""(bind [::]:60053
52+
audit-file /tmp/audit.log
53+
audit-enable yes
54+
server 127.0.0.1:61053
55+
)""");
56+
smartdns::Client client;
57+
ASSERT_TRUE(client.Query("a.com", 60053));
58+
std::cout << client.GetResult() << std::endl;
59+
ASSERT_EQ(client.GetAnswerNum(), 1);
60+
EXPECT_EQ(client.GetStatus(), "NOERROR");
61+
EXPECT_EQ(client.GetAnswer()[0].GetName(), "a.com");
62+
EXPECT_EQ(client.GetAnswer()[0].GetData(), "1.2.3.4");
63+
64+
std::ifstream audit_file("/tmp/audit.log");
65+
std::string line;
66+
bool found = false;
67+
while (std::getline(audit_file, line)) {
68+
if (line.find("a.com") != std::string::npos) {
69+
found = true;
70+
break;
71+
}
72+
}
73+
74+
audit_file.close();
75+
76+
ASSERT_TRUE(found) << "Audit log for a.com not found";
77+
}

0 commit comments

Comments
 (0)