Skip to content

Commit 1b5664a

Browse files
committed
Merge branch '29045_system_password_change' into 'larch-platform'
Change system password See merge request openlan/ols-ucentral-client!23
2 parents 6029b49 + 45e9aea commit 1b5664a

File tree

6 files changed

+71
-1
lines changed

6 files changed

+71
-1
lines changed

src/ucentral-client/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ platform/plat.a:
1919

2020
ucentral-client: ucentral-client.o proto.o platform/plat.a \
2121
ucentral-json-parser.o ucentral-log.o router-utils.o base64.o
22-
g++ -g -o $@ $^ -lcurl -lwebsockets -lcjson -lssl -lcrypto -lpthread -ljsoncpp -lresolv -lhiredis -ldbus-1
22+
g++ -g -o $@ $^ -lcurl -lwebsockets -lcjson -lssl -lcrypto -lpthread -ljsoncpp -lresolv -lhiredis -ldbus-1 -lcrypt
2323

2424
test:
2525
@echo "========= running unit tests ========="

src/ucentral-client/platform/larch-sonic/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ add_library(larch-sonic
3232
"state.cpp"
3333
"stp.cpp"
3434
"syslog.cpp"
35+
"system.cpp"
3536
"utils.cpp"
3637
"vlan.cpp"
3738
)

src/ucentral-client/platform/larch-sonic/host_service.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ INTERFACE(config)
1818
config() : INIT(reload), INIT(save) {}
1919
};
2020

21+
INTERFACE(system_password)
22+
{
23+
Method<simppl::dbus::in<std::string>, simppl::dbus::out<std::tuple<std::int32_t, std::string>>> update;
24+
25+
system_password() : INIT(update) {}
26+
};
27+
2128
} // namespace org::SONiC::HostService
2229

2330
#endif // !LARCH_PLATFORM_HOST_SERVICE_HPP_

src/ucentral-client/platform/larch-sonic/plat-larch.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <state.hpp>
77
#include <stp.hpp>
88
#include <syslog.hpp>
9+
#include <system.hpp>
910
#include <utils.hpp>
1011
#include <vlan.hpp>
1112

@@ -227,6 +228,7 @@ int plat_config_apply(struct plat_cfg *cfg, uint32_t id)
227228
apply_route_config(cfg);
228229
apply_stp_config(cfg);
229230
apply_services_config(cfg);
231+
apply_system_password_config(cfg);
230232
apply_vlan_ipv4_config(cfg);
231233
/* apply_syslog_config() call must always be the last one */
232234
apply_syslog_config(cfg->log_cfg, cfg->log_cfg_cnt);
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#include <host_service.hpp>
2+
#include <system.hpp>
3+
#include <utils.hpp>
4+
5+
#define UC_LOG_COMPONENT UC_LOG_COMPONENT_PLAT
6+
7+
#define HASH_SHA512_TYPE "$6$"
8+
#define HASH_SHA512_SALT "c53N"
9+
#define HASH_SHA512_CONFIG HASH_SHA512_TYPE HASH_SHA512_SALT
10+
11+
#include <crypt.h>
12+
#include <simppl/dispatcher.h>
13+
#include <simppl/stub.h>
14+
#include <ucentral-log.h>
15+
16+
namespace larch {
17+
18+
void apply_system_password_config(struct plat_cfg *cfg)
19+
{
20+
if (cfg->unit.system.password_changed)
21+
{
22+
try
23+
{
24+
struct crypt_data cd;
25+
memset(&cd, 0, sizeof cd);
26+
27+
std::string hash = crypt_r(cfg->unit.system.password, HASH_SHA512_CONFIG, &cd);
28+
29+
simppl::dbus::Dispatcher disp{"bus:system"};
30+
simppl::dbus::Stub<org::SONiC::HostService::system_password> stub{
31+
disp,
32+
"org.SONiC.HostService",
33+
"/org/SONiC/HostService/system_password"};
34+
35+
const auto ret = stub.update(hash);
36+
UC_LOG_INFO("system_password update returned %d: %s",
37+
std::get<0>(ret),
38+
std::get<1>(ret).c_str());
39+
}
40+
catch (const std::exception &ex)
41+
{
42+
UC_LOG_ERR("Failed to update system password: %s", ex.what());
43+
}
44+
45+
}
46+
}
47+
48+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef LARCH_PLATFORM_SYSTEM_HPP_
2+
#define LARCH_PLATFORM_SYSTEM_HPP_
3+
4+
#include <ucentral-platform.h>
5+
6+
namespace larch {
7+
8+
void apply_system_password_config(struct plat_cfg *cfg);
9+
10+
}
11+
12+
#endif // !LARCH_PLATFORM_SYSTEM_HPP_

0 commit comments

Comments
 (0)