@@ -38,10 +38,6 @@ struct sr_change {
38
38
sr_val_t * new ;
39
39
};
40
40
41
- static char * ver = NULL ;
42
- static char * rel = NULL ;
43
- static char * sys = NULL ;
44
- static char * os = NULL ;
45
41
static char * nm = NULL ;
46
42
static char * id = NULL ;
47
43
@@ -90,17 +86,9 @@ static void setvar(const char *line, const char *key, char **var)
90
86
91
87
static void os_init (void )
92
88
{
93
- struct utsname uts ;
94
89
char line [80 ];
95
90
FILE * fp ;
96
91
97
- if (!uname (& uts )) {
98
- os = strdup (uts .sysname );
99
- ver = strdup (uts .release );
100
- rel = strdup (uts .release );
101
- sys = strdup (uts .machine );
102
- }
103
-
104
92
fp = fopen ("/etc/os-release" , "r" );
105
93
if (!fp ) {
106
94
fp = fopen ("/usr/lib/os-release" , "r" );
@@ -110,36 +98,12 @@ static void os_init(void)
110
98
111
99
while (fgets (line , sizeof (line ), fp )) {
112
100
line [strlen (line ) - 1 ] = 0 ; /* drop \n */
113
- setvar (line , "NAME" , & os );
114
- setvar (line , "VERSION_ID" , & ver );
115
- setvar (line , "BUILD_ID" , & rel );
116
- setvar (line , "ARCHITECTURE" , & sys );
117
101
setvar (line , "DEFAULT_HOSTNAME" , & nm );
118
102
setvar (line , "ID" , & id );
119
103
}
120
104
fclose (fp );
121
105
}
122
106
123
- static char * fmtime (time_t t , char * buf , size_t len )
124
- {
125
- const char * isofmt = "%FT%T%z" ;
126
- struct tm tm ;
127
- size_t i , n ;
128
-
129
- tzset ();
130
- localtime_r (& t , & tm );
131
- n = strftime (buf , len , isofmt , & tm );
132
- i = n - 5 ;
133
- if (buf [i ] == '+' || buf [i ] == '-' ) {
134
- buf [i + 6 ] = buf [i + 5 ];
135
- buf [i + 5 ] = buf [i + 4 ];
136
- buf [i + 4 ] = buf [i + 3 ];
137
- buf [i + 3 ] = ':' ;
138
- }
139
-
140
- return buf ;
141
- }
142
-
143
107
static sr_error_t _sr_change_iter (sr_session_ctx_t * session , struct confd * confd , char * xpath ,
144
108
sr_error_t cb (sr_session_ctx_t * , struct confd * , struct sr_change * ))
145
109
{
@@ -165,71 +129,6 @@ static sr_error_t _sr_change_iter(sr_session_ctx_t *session, struct confd *confd
165
129
return SR_ERR_OK ;
166
130
}
167
131
168
- static int clock_cb (sr_session_ctx_t * session , uint32_t sub_id , const char * module ,
169
- const char * path , const char * request_path , uint32_t request_id ,
170
- struct lyd_node * * parent , void * priv )
171
- {
172
- static char boottime [64 ] = { 0 };
173
- const struct ly_ctx * ctx ;
174
- char curtime [64 ];
175
- time_t now , boot ;
176
- int rc ;
177
-
178
- ctx = sr_acquire_context (sr_session_get_connection (session ));
179
-
180
- now = time (NULL );
181
- if (!boottime [0 ]) {
182
- struct sysinfo si ;
183
-
184
- sysinfo (& si );
185
- boot = now - si .uptime ;
186
- fmtime (boot , boottime , sizeof (boottime ));
187
- }
188
- fmtime (now , curtime , sizeof (curtime ));
189
-
190
- if ((rc = lydx_new_path (ctx , parent , CLOCK_PATH_ , "boot-datetime" , "%s" , boottime )))
191
- goto fail ;
192
- if ((rc = lydx_new_path (ctx , parent , CLOCK_PATH_ , "current-datetime" , "%s" , curtime )))
193
- goto fail ;
194
-
195
- if (rc ) {
196
- fail :
197
- ERROR ("Failed building data tree, libyang error %d" , rc );
198
- rc = SR_ERR_INTERNAL ;
199
- }
200
-
201
- sr_release_context (sr_session_get_connection (session ));
202
- return rc ;
203
- }
204
-
205
- static int platform_cb (sr_session_ctx_t * session , uint32_t sub_id , const char * module ,
206
- const char * path , const char * request_path , uint32_t request_id ,
207
- struct lyd_node * * parent , void * priv )
208
- {
209
- const struct ly_ctx * ctx ;
210
- int rc ;
211
-
212
- ctx = sr_acquire_context (sr_session_get_connection (session ));
213
-
214
- if ((rc = lydx_new_path (ctx , parent , PLATFORM_PATH_ , "os-name" , "%s" , os )))
215
- goto fail ;
216
- if ((rc = lydx_new_path (ctx , parent , PLATFORM_PATH_ , "os-release" , "%s" , rel )))
217
- goto fail ;
218
- if ((rc = lydx_new_path (ctx , parent , PLATFORM_PATH_ , "os-version" , "%s" , ver )))
219
- goto fail ;
220
- if ((rc = lydx_new_path (ctx , parent , PLATFORM_PATH_ , "machine" , "%s" , sys )))
221
- goto fail ;
222
-
223
- if (rc ) {
224
- fail :
225
- ERROR ("Failed building data tree, libyang error %d" , rc );
226
- rc = SR_ERR_INTERNAL ;
227
- }
228
-
229
- sr_release_context (sr_session_get_connection (session ));
230
- return rc ;
231
- }
232
-
233
132
static int rpc_exec (sr_session_ctx_t * session , uint32_t sub_id , const char * path ,
234
133
const sr_val_t * input , const size_t input_cnt ,
235
134
sr_event_t event , unsigned request_id ,
@@ -1408,30 +1307,6 @@ static int change_auth(sr_session_ctx_t *session, uint32_t sub_id, const char *m
1408
1307
return SR_ERR_OK ;
1409
1308
}
1410
1309
1411
- static int auth_cb (sr_session_ctx_t * session , uint32_t sub_id , const char * module ,
1412
- const char * path , const char * request_path , uint32_t request_id ,
1413
- struct lyd_node * * parent , void * priv )
1414
- {
1415
- const char * fmt = "/ietf-system:system/authentication/user[name='%s']/password" ;
1416
- struct spwd * spwd ;
1417
-
1418
- setspent ();
1419
- while ((spwd = getspent ())) {
1420
- char xpath [256 ];
1421
-
1422
- /* Skip any records that do not pass YANG validation */
1423
- if (!spwd -> sp_pwdp || spwd -> sp_pwdp [0 ] == '0' ||
1424
- spwd -> sp_pwdp [0 ] == '*' || spwd -> sp_pwdp [0 ] == '!' )
1425
- continue ;
1426
-
1427
- snprintf (xpath , sizeof (xpath ), fmt , spwd -> sp_namp );
1428
- lyd_new_path (* parent , NULL , xpath , spwd -> sp_pwdp , 0 , 0 );
1429
- }
1430
- endspent ();
1431
-
1432
- return SR_ERR_OK ;
1433
- }
1434
-
1435
1310
static int change_nacm (sr_session_ctx_t * session , uint32_t sub_id , const char * module ,
1436
1311
const char * _ , sr_event_t event , unsigned request_id , void * priv )
1437
1312
{
@@ -1773,46 +1648,24 @@ static int change_hostname(sr_session_ctx_t *session, uint32_t sub_id, const cha
1773
1648
return SR_ERR_OK ;
1774
1649
}
1775
1650
1776
- static int hostname_cb (sr_session_ctx_t * session , uint32_t sub_id , const char * module ,
1777
- const char * path , const char * request_path , uint32_t request_id ,
1778
- struct lyd_node * * parent , void * priv )
1779
- {
1780
- char hostname [128 ];
1781
- int rc ;
1782
-
1783
- gethostname (hostname , sizeof (hostname ));
1784
- rc = lyd_new_path (* parent , NULL , path , hostname , 0 , NULL );
1785
- if (rc ) {
1786
- ERROR ("Failed building data tree, libyang error %d" , rc );
1787
- rc = SR_ERR_INTERNAL ;
1788
- }
1789
-
1790
- return rc ;
1791
- }
1792
-
1793
1651
int ietf_system_init (struct confd * confd )
1794
1652
{
1795
1653
int rc ;
1796
1654
1797
1655
os_init ();
1798
1656
1799
1657
REGISTER_CHANGE (confd -> session , "ietf-system" , XPATH_AUTH_ , 0 , change_auth , confd , & confd -> sub );
1800
- REGISTER_OPER (confd -> session , "ietf-system" , PASSWORD_PATH , auth_cb , confd , 0 , & confd -> sub );
1801
1658
REGISTER_MONITOR (confd -> session , "ietf-netconf-acm" , "/ietf-netconf-acm:nacm//." ,
1802
1659
0 , change_nacm , confd , & confd -> sub );
1803
1660
1804
1661
REGISTER_CHANGE (confd -> session , "ietf-system" , XPATH_BASE_ "/hostname" , 0 , change_hostname , confd , & confd -> sub );
1805
- REGISTER_OPER (confd -> session , "ietf-system" , XPATH_BASE_ "/hostname" , hostname_cb , confd , 0 , & confd -> sub );
1806
1662
REGISTER_CHANGE (confd -> session , "ietf-system" , XPATH_BASE_ "/infix-system:motd" , 0 , change_motd , confd , & confd -> sub );
1807
1663
REGISTER_CHANGE (confd -> session , "ietf-system" , XPATH_BASE_ "/infix-system:motd-banner" , 0 , change_motd_banner , confd , & confd -> sub );
1808
1664
REGISTER_CHANGE (confd -> session , "ietf-system" , XPATH_BASE_ "/infix-system:text-editor" , 0 , change_editor , confd , & confd -> sub );
1809
1665
REGISTER_CHANGE (confd -> session , "ietf-system" , XPATH_BASE_ "/clock" , 0 , change_clock , confd , & confd -> sub );
1810
1666
REGISTER_CHANGE (confd -> session , "ietf-system" , XPATH_BASE_ "/ntp" , 0 , change_ntp , confd , & confd -> sub );
1811
1667
REGISTER_CHANGE (confd -> session , "ietf-system" , XPATH_BASE_ "/dns-resolver" , 0 , change_dns , confd , & confd -> sub );
1812
1668
1813
- REGISTER_OPER (confd -> session , "ietf-system" , CLOCK_PATH_ , clock_cb , NULL , 0 , & confd -> sub );
1814
- REGISTER_OPER (confd -> session , "ietf-system" , PLATFORM_PATH_ , platform_cb , NULL , 0 , & confd -> sub );
1815
-
1816
1669
REGISTER_RPC (confd -> session , "/ietf-system:system-restart" , rpc_exec , "reboot" , & confd -> sub );
1817
1670
REGISTER_RPC (confd -> session , "/ietf-system:system-shutdown" , rpc_exec , "poweroff" , & confd -> sub );
1818
1671
REGISTER_RPC (confd -> session , "/ietf-system:set-current-datetime" , rpc_set_datetime , NULL , & confd -> sub );
0 commit comments