1
1
#!/usr/bin/env python3
2
2
#
3
- # Copyright (C) 2018-2023 VyOS maintainers and contributors
3
+ # Copyright (C) 2018-2024 VyOS maintainers and contributors
4
4
#
5
5
# This program is free software; you can redistribute it and/or modify
6
6
# it under the terms of the GNU General Public License version 2 or later as
26
26
from vyos .snmpv3_hashgen import plaintext_to_sha1
27
27
from vyos .snmpv3_hashgen import random
28
28
from vyos .template import render
29
- from vyos .utils .process import call
30
- from vyos .utils .permission import chmod_755
29
+ from vyos .utils .configfs import delete_cli_node
30
+ from vyos .utils .configfs import add_cli_node
31
31
from vyos .utils .dict import dict_search
32
32
from vyos .utils .network import is_addr_assigned
33
+ from vyos .utils .process import call
34
+ from vyos .utils .permission import chmod_755
33
35
from vyos .version import get_version_data
34
36
from vyos import ConfigError
35
37
from vyos import airbag
@@ -192,12 +194,8 @@ def generate(snmp):
192
194
return None
193
195
194
196
if 'v3' in snmp :
195
- # net-snmp is now regenerating the configuration file in the background
196
- # thus we need to re-open and re-read the file as the content changed.
197
- # After that we can no read the encrypted password from the config and
198
- # replace the CLI plaintext password with its encrypted version.
199
- os .environ ['vyos_libexec_dir' ] = '/usr/libexec/vyos'
200
-
197
+ # SNMPv3 uses a hashed password. If CLI defines a plaintext password,
198
+ # we will hash it in the background and replace the CLI node!
201
199
if 'user' in snmp ['v3' ]:
202
200
for user , user_config in snmp ['v3' ]['user' ].items ():
203
201
if dict_search ('auth.type' , user_config ) == 'sha' :
@@ -212,8 +210,9 @@ def generate(snmp):
212
210
snmp ['v3' ]['user' ][user ]['auth' ]['encrypted_password' ] = tmp
213
211
del snmp ['v3' ]['user' ][user ]['auth' ]['plaintext_password' ]
214
212
215
- call (f'/opt/vyatta/sbin/my_set service snmp v3 user "{ user } " auth encrypted-password "{ tmp } " > /dev/null' )
216
- call (f'/opt/vyatta/sbin/my_delete service snmp v3 user "{ user } " auth plaintext-password > /dev/null' )
213
+ cli_base = ['service' , 'snmp' , 'v3' , 'user' , user , 'auth' ]
214
+ delete_cli_node (cli_base + ['plaintext-password' ])
215
+ add_cli_node (cli_base + ['encrypted-password' ], value = tmp )
217
216
218
217
if dict_search ('privacy.plaintext_password' , user_config ) is not None :
219
218
tmp = hash (dict_search ('privacy.plaintext_password' , user_config ),
@@ -222,8 +221,9 @@ def generate(snmp):
222
221
snmp ['v3' ]['user' ][user ]['privacy' ]['encrypted_password' ] = tmp
223
222
del snmp ['v3' ]['user' ][user ]['privacy' ]['plaintext_password' ]
224
223
225
- call (f'/opt/vyatta/sbin/my_set service snmp v3 user "{ user } " privacy encrypted-password "{ tmp } " > /dev/null' )
226
- call (f'/opt/vyatta/sbin/my_delete service snmp v3 user "{ user } " privacy plaintext-password > /dev/null' )
224
+ cli_base = ['service' , 'snmp' , 'v3' , 'user' , user , 'privacy' ]
225
+ delete_cli_node (cli_base + ['plaintext-password' ])
226
+ add_cli_node (cli_base + ['encrypted-password' ], value = tmp )
227
227
228
228
# Write client config file
229
229
render (config_file_client , 'snmp/etc.snmp.conf.j2' , snmp )
@@ -246,7 +246,7 @@ def apply(snmp):
246
246
return None
247
247
248
248
# start SNMP daemon
249
- call (f'systemctl restart { systemd_service } ' )
249
+ call (f'systemctl reload-or- restart { systemd_service } ' )
250
250
251
251
# Enable AgentX in FRR
252
252
# This should be done for each daemon individually because common command
0 commit comments