Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
snmp_user2({create, Record0}) ->
map_table:maybe_transaction(
fun() ->
Record = maps:merge(#{engine_id=>local}, Record0),
snmp_user_create(Record)
end).
snmp_user_create(Record=#{ security_model := SecurityModel,
security_name := SecurityName,
access_type := AccessType})
when is_list(SecurityName),
(AccessType==readonly orelse AccessType==readwrite) ->
%% make sure SecurityName is not already present in table
case lists:member(SecurityName, map_table:all_keys(snmp_user)) of
true -> erlang:error(badarg, "security name exists");
false -> ok
end,
EngineId = engine_id(Record),
User = case Record of
#{security_model:=v2c, community_name:=CommunityName} when is_list(CommunityName) ->
#{ engine_id => EngineId,
security_model => SecurityModel,
security_name => SecurityName,
community_name => CommunityName,
access_type => AccessType};
#{security_model:=usm, user_name:=UserName, authp:=AuthP, privp:=PrivP} when is_list(UserName) ->
LocalizationHash = localization_hash(AuthP),
#{ security_model => SecurityModel,
user_name => UserName,
security_name => SecurityName,
engine_id => EngineId,
authp => authp(AuthP),
authkey => authkey(Record, LocalizationHash, EngineId),
privp => privp(PrivP),
privkey => privkey(Record, LocalizationHash, EngineId),
access_type => AccessType}
end,
map_table:write(snmp_user, SecurityModel, User).
engine_id(#{engine_id := E}) when is_list(E)->
E;
engine_id(#{engine_id := local}) ->
snmp_agent_controller:get_engine_id().
localization_hash(md5) -> md5;
localization_hash(sha) -> sha;
localization_hash(usmHMACMD5AuthProtocol) -> md5;
localization_hash(usmHMACSHAAuthProtocol) -> sha
authkey(#{authkey:=AuthK}, _, _) when is_list(AuthK) ->
AuthK;
authkey(#{authpassword:=AuthPass}, LocalizationHash, EngineId) when is_list(AuthPass) ->
snmp:passwd2localized_key(LocalizationHash, AuthPass, EngineId).
authp(md5) -> usmHMACMD5AuthProtocol;
authp(sha) -> usmHMACSHAAuthProtocol.
privp(des) -> usmDESPrivProtocol;
privp(aes) -> usmAesCfb128Protocol;
privp(PP) when PP==usmDESPrivProtocol; PP==usmAesCfb128Protocol ->
PP.
privkey(#{privkey:=PrivK}, _, _) when is_list(PrivK) -> PrivK;
privkey(#{privpassword:=PrivPass}, LocalizationHash, EngineId) when is_list(PrivPass) ->
lists:sublist(snmp:passwd2localized_key(LocalizationHash, PrivPass, EngineId), 16).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.