~ubuntu-branches/ubuntu/lucid/erlang/lucid-proposed

« back to all changes in this revision

Viewing changes to lib/snmp/src/manager/snmpm_config.erl

  • Committer: Bazaar Package Importer
  • Author(s): Sergei Golovan
  • Date: 2009-06-11 12:18:07 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090611121807-ks7eb4xrt7dsysgx
Tags: 1:13.b.1-dfsg-1
* New upstream release.
* Removed unnecessary dependency of erlang-os-mon on erlang-observer and
  erlang-tools and added missing dependency of erlang-nox on erlang-os-mon
  (closes: #529512).
* Removed a patch to eunit application because the bug was fixed upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
72
72
 
73
73
         load_mib/1, unload_mib/1, which_mibs/0, 
74
74
         make_mini_mib/0,
75
 
         name_to_oid/1, oid_to_name/1,
 
75
         name_to_oid/1, oid_to_name/1, oid_to_type/1, 
76
76
 
77
77
         system_start_time/0,
78
78
 
527
527
 
528
528
system_info(all) ->
529
529
    lists:sort(ets:tab2list(snmpm_config_table));
530
 
system_info(Key) when atom(Key) ->
 
530
system_info(Key) when is_atom(Key) ->
531
531
    case ets:lookup(snmpm_config_table, Key) of
532
532
        [{_, Val}] ->
533
533
            {ok, Val};
633
633
set_engine_time(Time) ->
634
634
    call({set_engine_time, Time}).
635
635
 
636
 
register_usm_user(EngineID, Name, Config) when list(EngineID), list(Name) ->
 
636
register_usm_user(EngineID, Name, Config) 
 
637
  when is_list(EngineID) andalso is_list(Name) ->
637
638
    case verify_usm_user_config(EngineID, Name, Config) of
638
639
        {ok, User} ->
639
640
            call({register_usm_user, User});
641
642
            Error
642
643
    end.
643
644
 
644
 
unregister_usm_user(EngineID, Name) when list(EngineID), list(Name) ->
 
645
unregister_usm_user(EngineID, Name) 
 
646
  when is_list(EngineID) andalso is_list(Name) ->
645
647
    call({unregister_usm_user, EngineID, Name}).
646
648
 
647
649
verify_usm_user_config(EngineID, Name, Config) ->
717
719
    {error, {bad_iten, Item}}.
718
720
 
719
721
update_usm_user_info(EngineID, UserName, Item, Val) 
720
 
  when Item =/= engine_id, Item =/= name ->
 
722
  when (Item =/= engine_id) andalso (Item =/= name) ->
721
723
    call({update_usm_user_info, EngineID, UserName, Item, Val}).
722
724
 
723
725
get_usm_user(EngineID, UserName) ->
827
829
get_stats_counters() ->
828
830
    ets:tab2list(snmpm_stats_table).
829
831
    
830
 
load_mib(Mib) when list(Mib) ->
 
832
load_mib(Mib) when is_list(Mib) ->
831
833
    call({load_mib, Mib}).
832
834
 
833
 
unload_mib(Mib) when list(Mib) ->
 
835
unload_mib(Mib) when is_list(Mib) ->
834
836
    call({unload_mib, Mib}).
835
837
 
836
838
which_mibs() ->
856
858
            {error, not_found}
857
859
    end.
858
860
 
 
861
oid_to_type(Oid) ->
 
862
    case ets:lookup(snmpm_mib_table, {mini_mib, Oid}) of
 
863
        [{_, _, Type, _}] ->
 
864
            {ok, Type};
 
865
        [] ->
 
866
            {error, not_found}
 
867
    end.
 
868
 
859
869
make_mini_mib() ->
860
870
    Pat = {{mini_mib, '$1'}, '$2', '$3', '_'},
861
871
    MiniElems = ets:match(snmpm_mib_table, Pat),
1205
1215
verify_option(Opt) ->
1206
1216
    {error, {invalid_option, Opt}}.
1207
1217
 
1208
 
verify_prio(Prio) when atom(Prio) ->
 
1218
verify_prio(Prio) when is_atom(Prio) ->
1209
1219
    ok;
1210
1220
verify_prio(Prio) ->
1211
1221
    error({invalid_prio, Prio}).
1214
1224
    ok;
1215
1225
verify_irb(user) ->
1216
1226
    ok;
1217
 
verify_irb({user, To}) when is_integer(To) and (To > 0) ->
 
1227
verify_irb({user, To}) when is_integer(To) andalso (To > 0) ->
1218
1228
    ok;
1219
1229
verify_irb(IRB) ->
1220
1230
    error({invalid_irb, IRB}).
1221
1231
 
1222
1232
verify_mibs([]) ->
1223
1233
    ok;
1224
 
verify_mibs([Mib|Mibs]) when list(Mib) ->
 
1234
verify_mibs([Mib|Mibs]) when is_list(Mib) ->
1225
1235
    verify_mibs(Mibs);
1226
1236
verify_mibs(Mibs) ->
1227
1237
    error({invalid_mibs, Mibs}).
1260
1270
verify_server_opts([Opt|_]) ->
1261
1271
    error({invalid_server_option, Opt}).
1262
1272
 
1263
 
verify_server_timeout(T) when integer(T), T > 0 ->
 
1273
verify_server_timeout(T) when is_integer(T) andalso (T > 0) ->
1264
1274
    ok;
1265
1275
verify_server_timeout(T) ->
1266
1276
    error({invalid_server_timeout, T}).
1273
1283
verify_net_if_opts([{verbosity, Verbosity}|Opts]) ->
1274
1284
    verify_verbosity(Verbosity),
1275
1285
    verify_net_if_opts(Opts);
1276
 
verify_net_if_opts([{options, Options}|Opts]) when list(Options) ->
 
1286
verify_net_if_opts([{options, Options}|Opts]) when is_list(Options) ->
1277
1287
    verify_net_if_opts(Opts);
1278
1288
verify_net_if_opts([Opt|_]) ->
1279
1289
    error({invalid_net_if_option, Opt}).
1298
1308
verify_note_store_opts([Opt|_]) ->
1299
1309
    error({invalid_note_store_option, Opt}).
1300
1310
 
1301
 
verify_note_store_timeout(T) when integer(T), T > 0 ->
 
1311
verify_note_store_timeout(T) when is_integer(T) andalso (T > 0) ->
1302
1312
    ok;
1303
1313
verify_note_store_timeout(T) ->
1304
1314
    error({invalid_note_store_timeout, T}).
1344
1354
 
1345
1355
verify_conf_auto_save(infinity) ->
1346
1356
    ok;
1347
 
verify_conf_auto_save(AutoSave) when integer(AutoSave), AutoSave > 0 ->
 
1357
verify_conf_auto_save(AutoSave) 
 
1358
  when is_integer(AutoSave) andalso (AutoSave > 0) ->
1348
1359
    ok;
1349
1360
verify_conf_auto_save(InvalidAutoSave) ->
1350
1361
    error({invalid_conf_db_auto_save, InvalidAutoSave}).
1401
1412
            error({invalid_audit_trail_log_dir, Dir})
1402
1413
    end.
1403
1414
 
1404
 
verify_log_size(Sz) when integer(Sz), Sz > 0 ->
 
1415
verify_log_size(Sz) when is_integer(Sz) andalso (Sz > 0) ->
1405
1416
    ok;
1406
1417
verify_log_size(infinity) ->
1407
1418
    ok;
1408
1419
verify_log_size({MaxNoBytes, MaxNoFiles}) 
1409
 
  when integer(MaxNoBytes), MaxNoBytes > 0,
1410
 
       integer(MaxNoFiles), MaxNoFiles > 0, MaxNoFiles < 65000 ->
 
1420
  when (is_integer(MaxNoBytes) andalso 
 
1421
        (MaxNoBytes > 0) andalso 
 
1422
        is_integer(MaxNoFiles) andalso 
 
1423
        (MaxNoFiles > 0) andalso 
 
1424
        (MaxNoFiles < 65000)) ->
1411
1425
    ok;
1412
1426
verify_log_size(Sz) ->
1413
1427
    error({invalid_audit_trail_log_size, Sz}).
1419
1433
    error({invalid_audit_trail_log_repair, Repair}).
1420
1434
 
1421
1435
 
1422
 
verify_module(_, Mod) when atom(Mod) ->
 
1436
verify_module(_, Mod) when is_atom(Mod) ->
1423
1437
    ok;
1424
1438
verify_module(ReasonTag, Mod) ->
1425
1439
    error({invalid_module, ReasonTag, Mod}).
1431
1445
% verify_bool(ReasonTag, Bool) ->
1432
1446
%     error({invalid_bool, ReasonTag, Bool}).
1433
1447
 
1434
 
verify_dir(Dir) when list(Dir) ->
 
1448
verify_dir(Dir) when is_list(Dir) ->
1435
1449
    case file:read_file_info(Dir) of
1436
1450
        {ok, #file_info{type = directory}} ->
1437
1451
            ok;
1754
1768
    init_usm_user_config(User),
1755
1769
    init_usm_users_config(Users).
1756
1770
 
1757
 
init_usm_user_config(User) when record(User, usm_user) ->
 
1771
init_usm_user_config(User) when is_record(User, usm_user) ->
1758
1772
    case handle_register_usm_user(User) of
1759
1773
        ok ->
1760
1774
            ok;
1825
1839
            error({invalid_auth_key, usmNoAuthProtocol})
1826
1840
    end;
1827
1841
verify_usm_user_auth(usmHMACMD5AuthProtocol, AuthKey) 
1828
 
  when list(AuthKey), length(AuthKey) == 16 ->
 
1842
  when is_list(AuthKey) andalso (length(AuthKey) =:= 16) ->
1829
1843
    case is_crypto_supported(md5_mac_96) of
1830
1844
        true -> 
1831
1845
            case snmp_conf:all_integer(AuthKey) of
1837
1851
        false -> 
1838
1852
            error({unsupported_crypto, md5_mac_96})
1839
1853
    end;    
1840
 
verify_usm_user_auth(usmHMACMD5AuthProtocol, AuthKey) when list(AuthKey) ->
 
1854
verify_usm_user_auth(usmHMACMD5AuthProtocol, AuthKey) when is_list(AuthKey) ->
1841
1855
    Len = length(AuthKey),
1842
1856
    error({invalid_auth_key, usmHMACMD5AuthProtocol, Len});
1843
1857
verify_usm_user_auth(usmHMACMD5AuthProtocol, _AuthKey) ->
1844
1858
    error({invalid_auth_key, usmHMACMD5AuthProtocol});
1845
1859
verify_usm_user_auth(usmHMACSHAAuthProtocol, AuthKey) 
1846
 
  when list(AuthKey), length(AuthKey) == 20 ->
 
1860
  when is_list(AuthKey) andalso (length(AuthKey) =:= 20) ->
1847
1861
    case is_crypto_supported(sha_mac_96) of
1848
1862
        true -> 
1849
1863
            case snmp_conf:all_integer(AuthKey) of
1855
1869
        false -> 
1856
1870
            error({unsupported_crypto, sha_mac_96})
1857
1871
    end;
1858
 
verify_usm_user_auth(usmHMACSHAAuthProtocol, AuthKey) when list(AuthKey) ->
 
1872
verify_usm_user_auth(usmHMACSHAAuthProtocol, AuthKey) when is_list(AuthKey) ->
1859
1873
    Len = length(AuthKey),
1860
1874
    error({invalid_auth_key, usmHMACSHAAuthProtocol, Len});
1861
1875
verify_usm_user_auth(usmHMACSHAAuthProtocol, _AuthKey) ->
1871
1885
            error({invalid_priv_key, usmNoPrivProtocol})
1872
1886
    end;
1873
1887
verify_usm_user_priv(usmDESPrivProtocol, PrivKey) 
1874
 
  when length(PrivKey) == 16 ->
 
1888
  when (length(PrivKey) =:= 16) ->
1875
1889
    case is_crypto_supported(des_cbc_decrypt) of
1876
1890
        true -> 
1877
1891
            case snmp_conf:all_integer(PrivKey) of
1883
1897
        false -> 
1884
1898
            error({unsupported_crypto, des_cbc_decrypt})
1885
1899
    end;
1886
 
verify_usm_user_priv(usmDESPrivProtocol, PrivKey) when list(PrivKey) ->
 
1900
verify_usm_user_priv(usmDESPrivProtocol, PrivKey) when is_list(PrivKey) ->
1887
1901
    Len = length(PrivKey),
1888
1902
    error({invalid_priv_key, usmDESPrivProtocol, Len});
1889
1903
verify_usm_user_priv(usmDESPrivProtocol, _PrivKey) ->
1890
1904
    error({invalid_priv_key, usmDESPrivProtocol});
1891
1905
verify_usm_user_priv(usmAesCfb128Protocol, PrivKey) 
1892
 
  when length(PrivKey) == 16 ->
 
1906
  when (length(PrivKey) =:= 16) ->
1893
1907
    case is_crypto_supported(aes_cfb_128_decrypt) of
1894
1908
        true -> 
1895
1909
            case snmp_conf:all_integer(PrivKey) of
1901
1915
        false -> 
1902
1916
            error({unsupported_crypto, aes_cfb_128_decrypt})
1903
1917
    end;
1904
 
verify_usm_user_priv(usmAesCfb128Protocol, PrivKey) when list(PrivKey) ->
 
1918
verify_usm_user_priv(usmAesCfb128Protocol, PrivKey) when is_list(PrivKey) ->
1905
1919
    Len = length(PrivKey),
1906
1920
    error({invalid_priv_key, usmAesCfb128Protocol, Len});
1907
1921
verify_usm_user_priv(usmAesCfb128Protocol, _PrivKey) ->
2301
2315
 
2302
2316
stop_backup_server(undefined) ->
2303
2317
    ok;
2304
 
stop_backup_server({Pid, _}) when pid(Pid) ->
 
2318
stop_backup_server({Pid, _}) when is_pid(Pid) ->
2305
2319
    exit(Pid, kill).
2306
2320
 
2307
2321
 
2635
2649
    end;    
2636
2650
do_update_usm_user_info(_Key, 
2637
2651
                        #usm_user{auth = usmHMACMD5AuthProtocol}, 
2638
 
                        auth_key, Val) when list(Val) ->
 
2652
                        auth_key, Val) when is_list(Val) ->
2639
2653
    Len = length(Val),
2640
2654
    {error, {invalid_auth_key_length, usmHMACMD5AuthProtocol, Len}};
2641
2655
do_update_usm_user_info(_Key, 
2645
2659
do_update_usm_user_info(Key, 
2646
2660
                        #usm_user{auth = usmHMACSHAAuthProtocol} = User, 
2647
2661
                        auth_key, Val) 
2648
 
  when length(Val) == 20 ->
 
2662
  when length(Val) =:= 20 ->
2649
2663
    case is_crypto_supported(sha_mac_96) of
2650
2664
        true -> 
2651
2665
            do_update_usm_user_info(Key, User#usm_user{auth_key = Val});
2654
2668
    end;    
2655
2669
do_update_usm_user_info(_Key, 
2656
2670
                        #usm_user{auth = usmHMACSHAAuthProtocol}, 
2657
 
                        auth_key, Val) when list(Val) ->
 
2671
                        auth_key, Val) when is_list(Val) ->
2658
2672
    Len = length(Val),
2659
2673
    {error, {invalid_auth_key_length, usmHMACSHAAuthProtocol, Len}};
2660
2674
do_update_usm_user_info(_Key, 
2662
2676
                        auth_key, Val) ->
2663
2677
    {error, {invalid_auth_key, usmHMACSHAAuthProtocol, Val}};
2664
2678
do_update_usm_user_info(Key, User, priv, Val) 
2665
 
  when Val == usmNoPrivProtocol; 
2666
 
       Val == usmDESPrivProtocol;
2667
 
       Val == usmAesCfb128Protocol ->
 
2679
  when (Val =:= usmNoPrivProtocol) orelse 
 
2680
       (Val =:= usmDESPrivProtocol) orelse
 
2681
       (Val =:= usmAesCfb128Protocol) ->
2668
2682
    do_update_usm_user_info(Key, User#usm_user{priv = Val});
2669
2683
do_update_usm_user_info(_Key, _User, priv, Val) ->
2670
2684
    {error, {invalid_priv_protocol, Val}};
2680
2694
do_update_usm_user_info(Key, 
2681
2695
                        #usm_user{priv = usmDESPrivProtocol} = User, 
2682
2696
                        priv_key, Val) 
2683
 
  when length(Val) == 16 ->
 
2697
  when length(Val) =:= 16 ->
2684
2698
    case is_crypto_supported(des_cbc_decrypt) of
2685
2699
        true -> 
2686
2700
            do_update_usm_user_info(Key, User#usm_user{priv_key = Val});
2690
2704
do_update_usm_user_info(Key, 
2691
2705
                        #usm_user{priv = usmAesCfb128Protocoll} = User, 
2692
2706
                        priv_key, Val) 
2693
 
  when length(Val) == 16 ->
 
2707
  when length(Val) =:= 16 ->
2694
2708
    case is_crypto_supported(aes_cfb_128_decrypt) of
2695
2709
        true -> 
2696
2710
            do_update_usm_user_info(Key, User#usm_user{priv_key = Val});
2699
2713
    end;    
2700
2714
do_update_usm_user_info(_Key, 
2701
2715
                        #usm_user{auth = usmHMACSHAAuthProtocol}, 
2702
 
                        priv_key, Val) when list(Val) ->
 
2716
                        priv_key, Val) when is_list(Val) ->
2703
2717
    Len = length(Val),
2704
2718
    {error, {invalid_priv_key_length, usmHMACSHAAuthProtocol, Len}};
2705
2719
do_update_usm_user_info(_Key, 
2851
2865
        false ->
2852
2866
            Mibs = [Mib|Mibs0],
2853
2867
            case (catch do_load_mib(Mib)) of
2854
 
                MiniElems when list(MiniElems) ->
 
2868
                MiniElems when is_list(MiniElems) ->
2855
2869
                    ets:insert(snmpm_config_table, {mibs, Mibs}),
2856
2870
                    update_mini_mib(MiniElems),
2857
2871
                    ok;
2862
2876
 
2863
2877
update_mini_mib([]) ->
2864
2878
    ok;
2865
 
update_mini_mib([{Oid, N, Type, MibName}|Elems]) ->
 
2879
update_mini_mib([{Oid, Name, Type, MibName}|Elems]) ->
2866
2880
    Key = {mini_mib, Oid},
2867
2881
    case ets:lookup(snmpm_mib_table, Key) of
2868
 
        [{Key, _N, _Type, _AnotherMibName}] ->
 
2882
        [{Key, _Name, _Type, _AnotherMibName}] ->
2869
2883
            %% Already loaded from another mib
2870
2884
            update_mini_mib(Elems);
2871
2885
        [] ->
2872
2886
            %% Not yet loaded
2873
 
            ets:insert(snmpm_mib_table, {Key, N, Type, MibName}),
 
2887
            ?vtrace("update mini mib -> ~w: ~w [~w] from ~s", 
 
2888
                    [Name, Oid, Type, MibName]),    
 
2889
            ets:insert(snmpm_mib_table, {Key, Name, Type, MibName}),
2874
2890
            update_mini_mib(Elems)
2875
2891
    end.
2876
2892
 
2928
2944
            error({failed_reading_mib, MibFile, Reason})
2929
2945
    end.
2930
2946
 
2931
 
mib_name(N) when list(N) ->
 
2947
mib_name(N) when is_list(N) ->
2932
2948
    list_to_atom(N);
2933
2949
mib_name(N) ->
2934
2950
    N.
3048
3064
                  {user,    UserSz}, 
3049
3065
                  {usm,     UsmSz}]}].
3050
3066
 
3051
 
proc_mem(P) when pid(P) ->
 
3067
proc_mem(P) when is_pid(P) ->
3052
3068
    case (catch erlang:process_info(P, memory)) of
3053
3069
        {memory, Sz} when is_integer(Sz) ->
3054
3070
            Sz;