snmp_user_based_sm_mib.erl
来自「OTP是开放电信平台的简称」· ERL 代码 · 共 1,101 行 · 第 1/3 页
ERL
1,101 行
snmp_generic:variable_func(set, Val, {usmUserSpinLock, volatile});usmUserSpinLock(delete) -> ok;usmUserSpinLock(get) -> snmp_generic:variable_func(get, {usmUserSpinLock, volatile}).usmUserSpinLock(is_set_ok, NewVal) -> case snmp_generic:variable_func(get, {usmUserSpinLock, volatile}) of {value, NewVal} -> noError; _ -> inconsistentValue end;usmUserSpinLock(set, NewVal) -> snmp_generic:variable_func(set, (NewVal + 1) rem 2147483648, {usmUserSpinLock, volatile}).%% Op == new | deleteusmUserTable(Op) -> snmp_generic:table_func(Op, db(usmUserTable)).%% Op == get | is_set_ok | set | get_nextusmUserTable(get, RowIndex, Cols) -> get_patch(Cols, get(usmUserTable, RowIndex, Cols));usmUserTable(get_next, RowIndex, Cols) -> next_patch(next(usmUserTable, RowIndex, Cols));usmUserTable(is_set_ok, RowIndex, Cols0) -> ?vtrace("usmUserTable(is_set_ok) -> entry with" "~n RowIndex: ~p" "~n Cols0: ~p", [RowIndex, Cols0]), case (catch verify_usmUserTable_cols(Cols0, [])) of {ok, Cols} -> ?vtrace("usmUserTable(is_set_ok) -> verified: " "~n Cols: ~p", [Cols]), %% Add a dummy value for securityName; otherwise snmp_generic will %% think that a value is missing, so the row can't be created. %% Note: this value is only added for is_set_ok, not for set! NCols = [{?usmUserSecurityName, ""} | Cols], IsSetOkRes = snmp_generic:table_func(is_set_ok, RowIndex, NCols, db(usmUserTable)), ?vtrace("usmUserTable(is_set_ok) -> tested: " "~n IsSetOkRes: ~p", [IsSetOkRes]), validate_is_set_ok(IsSetOkRes, RowIndex, Cols); Error -> Error end;usmUserTable(set, RowIndex, Cols0) -> ?vtrace("usmUserTable(set) -> entry with" "~n RowIndex: ~p" "~n Cols0: ~p", [RowIndex, Cols0]), case (catch verify_usmUserTable_cols(Cols0, [])) of {ok, Cols} -> ?vtrace("usmUserTable(set) -> verified" "~n Cols: ~p", [Cols]), NCols = pre_set(RowIndex, Cols), ?vtrace("usmUserTable(set) -> pre-set: " "~n NCols: ~p", [NCols]), %% NOTE: The NCols parameter is sent to snmp_generic, but not to %% validate_set! The reason is that the columns from pre_set are %% set in snmp_generic, but not used by validate_set. validate_set(snmp_generic:table_func(set, RowIndex, NCols, db(usmUserTable)), RowIndex, Cols); Error -> Error end;usmUserTable(Op, Arg1, Arg2) -> snmp_generic:table_func(Op, Arg1, Arg2, db(usmUserTable)).verify_usmUserTable_cols([], Cols) -> ?vtrace("verify_usmUserTable_cols -> entry when done with" "~n Cols: ~p", [Cols]), {ok, lists:reverse(Cols)};verify_usmUserTable_cols([{Col, Val0}|Cols], Acc) -> ?vtrace("verify_usmUserTable_cols -> entry with" "~n Col: ~p" "~n Val0: ~p", [Col, Val0]), Val = verify_usmUserTable_col(Col, Val0), ?vtrace("verify_usmUserTable_cols -> verified: " "~n Val: ~p", [Val]), verify_usmUserTable_cols(Cols, [{Col, Val}|Acc]).verify_usmUserTable_col(?usmUserEngineID, EngineID) -> case (catch snmp_conf:check_string(EngineID)) of ok -> EngineID; _ -> wrongValue(?usmUserEngineID) end;verify_usmUserTable_col(?usmUserName, Name) -> case (catch snmp_conf:check_string(Name)) of ok -> Name; _ -> wrongValue(?usmUserName) end;verify_usmUserTable_col(?usmUserSecurityName, Name) -> case (catch snmp_conf:check_string(Name)) of ok -> Name; _ -> wrongValue(?usmUserSecurityName) end;verify_usmUserTable_col(?usmUserCloneFrom, Clone) -> case Clone of zeroDotZero -> ?zeroDotZero; ?zeroDotZero -> ?zeroDotZero; _ -> case (catch snmp_conf:check_oid(Clone)) of ok -> Clone; _ -> wrongValue(?usmUserCloneFrom) end end;verify_usmUserTable_col(?usmUserAuthProtocol, AuthP) -> case AuthP of usmNoAuthProtocol -> ?usmNoAuthProtocol; usmHMACSHAAuthProtocol -> ?usmHMACSHAAuthProtocol; usmHMACMD5AuthProtocol -> ?usmHMACMD5AuthProtocol; ?usmNoAuthProtocol -> ?usmNoAuthProtocol; ?usmHMACSHAAuthProtocol -> ?usmHMACSHAAuthProtocol; ?usmHMACMD5AuthProtocol -> ?usmHMACMD5AuthProtocol; _ -> wrongValue(?usmUserAuthProtocol) end;verify_usmUserTable_col(?usmUserAuthKeyChange, AKC) -> case (catch snmp_conf:check_string(AKC)) of ok -> AKC; _ -> wrongValue(?usmUserAuthKeyChange) end;verify_usmUserTable_col(?usmUserOwnAuthKeyChange, OAKC) -> case (catch snmp_conf:check_string(OAKC)) of ok -> OAKC; _ -> wrongValue(?usmUserOwnAuthKeyChange) end;verify_usmUserTable_col(?usmUserPrivProtocol, PrivP) -> case PrivP of usmNoPrivProtocol -> ?usmNoPrivProtocol; usmDESPrivProtocol -> ?usmDESPrivProtocol; usmAesCfb128Protocol -> ?usmAesCfb128Protocol; ?usmNoPrivProtocol -> ?usmNoPrivProtocol; ?usmDESPrivProtocol -> ?usmDESPrivProtocol; ?usmAesCfb128Protocol -> ?usmAesCfb128Protocol; _ -> wrongValue(?usmUserPrivProtocol) end;verify_usmUserTable_col(?usmUserPrivKeyChange, PKC) -> case (catch snmp_conf:check_string(PKC)) of ok -> PKC; _ -> wrongValue(?usmUserPrivKeyChange) end;verify_usmUserTable_col(?usmUserOwnPrivKeyChange, OPKC) -> case (catch snmp_conf:check_string(OPKC)) of ok -> OPKC; _ -> wrongValue(?usmUserOwnPrivKeyChange) end;verify_usmUserTable_col(?usmUserPublic, Public) -> case (catch snmp_conf:check_string(Public)) of ok -> Public; _ -> wrongValue(?usmUserPublic) end;verify_usmUserTable_col(_, Val) -> Val. %% Patch the values stored in the DB with other values for some%% objects.get_patch([?usmUserCloneFrom | Cols], [{value, _Val} | Vals]) -> [{value, ?zeroDotZero} | get_patch(Cols, Vals)];get_patch([?usmUserAuthKeyChange | Cols], [{value, _Val} | Vals]) -> [{value, ""} | get_patch(Cols, Vals)];get_patch([?usmUserOwnAuthKeyChange | Cols], [{value, _Val} | Vals]) -> [{value, ""} | get_patch(Cols, Vals)];get_patch([?usmUserPrivKeyChange | Cols], [{value, _Val} | Vals]) -> [{value, ""} | get_patch(Cols, Vals)];get_patch([?usmUserOwnPrivKeyChange | Cols], [{value, _Val} | Vals]) -> [{value, ""} | get_patch(Cols, Vals)];get_patch([_Col | Cols], [Val | Vals]) -> [Val | get_patch(Cols, Vals)];get_patch(_Cols, Result) -> Result.next_patch([{[?usmUserCloneFrom | Idx], _Val} | Vals]) -> [{[?usmUserCloneFrom | Idx], ?zeroDotZero} | next_patch(Vals)];next_patch([{[?usmUserAuthKeyChange | Idx], _Val} | Vals]) -> [{[?usmUserAuthKeyChange | Idx], ""} | next_patch(Vals)];next_patch([{[?usmUserOwnAuthKeyChange | Idx], _Val} | Vals]) -> [{[?usmUserOwnAuthKeyChange | Idx], ""} | next_patch(Vals)];next_patch([{[?usmUserPrivKeyChange | Idx], _Val} | Vals]) -> [{[?usmUserPrivKeyChange | Idx], ""} | next_patch(Vals)];next_patch([{[?usmUserOwnPrivKeyChange | Idx], _Val} | Vals]) -> [{[?usmUserOwnPrivKeyChange | Idx], ""} | next_patch(Vals)];next_patch([Val | Vals]) -> [Val | next_patch(Vals)];next_patch(Result) -> Result.validate_is_set_ok({noError, 0}, RowIndex, Cols) -> case (catch do_validate_is_set_ok(RowIndex, Cols)) of ok -> {noError, 0}; Error -> Error end;validate_is_set_ok(Error, _RowIndex, _Cols) -> Error.do_validate_is_set_ok(RowIndex, Cols) -> validate_clone_from(RowIndex, Cols), validate_auth_protocol(RowIndex, Cols), validate_auth_key_change(RowIndex, Cols), validate_own_auth_key_change(RowIndex, Cols), validate_priv_protocol(RowIndex, Cols), validate_priv_key_change(RowIndex, Cols), validate_own_priv_key_change(RowIndex, Cols), ok. pre_set(RowIndex, Cols) -> %% Possibly initialize the usmUserSecurityName and privacy keys case snmp_generic:table_row_exists(db(usmUserTable), RowIndex) of true -> Cols; false -> SecName = get_user_name(RowIndex), [{?usmUserSecurityName, SecName} | Cols] ++ [{?usmUserAuthKey, ""}, {?usmUserPrivKey, ""}] end.validate_set({noError, 0}, RowIndex, Cols) -> %% Now, all is_set_ok validation steps have been executed. So %% everything is ready for the set. set_clone_from(RowIndex, Cols), set_auth_key_change(RowIndex, Cols), set_own_auth_key_change(RowIndex, Cols), set_priv_key_change(RowIndex, Cols), set_own_priv_key_change(RowIndex, Cols), {noError, 0};validate_set(Error, _RowIndex, _Cols) -> Error.%%-----------------------------------------------------------------%% Here's the alg: If this is the first time the CloneFrom is written,%% we must check that the CloneFrom row exists, so we can invoke the%% clone process in the set phase. Otherwise, the set succed, with%% no further checks.%%-----------------------------------------------------------------validate_clone_from(RowIndex, Cols) -> case lists:keysearch(?usmUserCloneFrom, 1, Cols) of {value, {_Col, RowPointer}} -> RowIndex2 = extract_row(RowPointer), OldCloneFrom = snmp_generic:table_get_element(db(usmUserTable), RowIndex, ?usmUserCloneFrom), case OldCloneFrom of {value, Val} when Val /= noinit -> %% This means that the cloning is already done... ok; _ -> %% Otherwise, we must check the CloneFrom value case snmp_generic:table_get_element(db(usmUserTable), RowIndex2, ?usmUserStatus) of {value, ?'RowStatus_active'} -> ok; _ -> inconsistentName(?usmUserCloneFrom) end end; false -> ok end.validate_auth_protocol(RowIndex, Cols) -> case lists:keysearch(?usmUserAuthProtocol, 1, Cols) of {value, {_Col, AuthProtocol}} -> %% Check if the row has been cloned; we can't check the %% old value of authProtocol, because if the row was %% createAndWaited, the default value would have been %% written (usmNoAuthProtocol). OldCloneFrom = snmp_generic:table_get_element(db(usmUserTable), RowIndex, ?usmUserCloneFrom), case OldCloneFrom of {value, Val} when Val /= noinit -> %% This means that the cloning is already done; set is ok %% if new protocol is usmNoAuthProtocol case AuthProtocol of ?usmNoAuthProtocol -> %% Check that the Priv protocl is noPriv case get_priv_proto(RowIndex, Cols) of ?usmNoPrivProtocol -> ok; _ -> inconsistentValue(?usmUserAuthProtocol) end; ?usmHMACMD5AuthProtocol -> inconsistentValue(?usmUserAuthProtocol); ?usmHMACSHAAuthProtocol -> inconsistentValue(?usmUserAuthProtocol); _ -> wrongValue(?usmUserAuthProtocol) end; _ -> %% Otherwise, check that the new protocol is known, %% and that the system we're running supports the %% hash function. case AuthProtocol of ?usmNoAuthProtocol -> %% Check that the Priv protocl is noPriv case get_priv_proto(RowIndex, Cols) of ?usmNoPrivProtocol -> ok; _ -> inconsistentValue(?usmUserAuthProtocol) end; ?usmHMACMD5AuthProtocol -> case is_crypto_supported(md5_mac_96) of true -> ok; false -> wrongValue(?usmUserAuthProtocol) end; ?usmHMACSHAAuthProtocol -> case is_crypto_supported(sha_mac_96) of true -> ok; false -> wrongValue(?usmUserAuthProtocol) end; _ -> wrongValue(?usmUserAuthProtocol) end end; false -> ok end.validate_auth_key_change(RowIndex, Cols) -> validate_key_change(RowIndex, Cols, ?usmUserAuthKeyChange, auth).validate_own_auth_key_change(RowIndex, Cols) -> validate_requester(RowIndex, Cols, ?usmUserOwnAuthKeyChange), validate_key_change(RowIndex, Cols, ?usmUserOwnAuthKeyChange, auth).validate_priv_key_change(RowIndex, Cols) -> validate_key_change(RowIndex, Cols, ?usmUserPrivKeyChange, priv).validate_own_priv_key_change(RowIndex, Cols) -> validate_requester(RowIndex, Cols, ?usmUserOwnPrivKeyChange), validate_key_change(RowIndex, Cols, ?usmUserOwnPrivKeyChange, priv).%% Check that the requesting user is the same as the modified uservalidate_requester(RowIndex, Cols, KeyChangeCol) -> case lists:keysearch(KeyChangeCol, 1, Cols) of {value, _} -> case get(sec_model) of % Check the securityModel in the request ?SEC_USM -> ok; _ -> noAccess(KeyChangeCol) end, %% The SecurityName may not be set yet. First, check if it is set. SecNameForUser = case snmp_generic:table_get_element(db(usmUserTable),
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?