snmpusm.h
上传用户:wxp200602
上传日期:2007-10-30
资源大小:4028k
文件大小:11k
源码类别:

SNMP编程

开发平台:

Unix_Linux

  1. /*
  2.  * snmpusm.h
  3.  *
  4.  * Header file for USM support.
  5.  */
  6. #ifndef SNMPUSM_H
  7. #define SNMPUSM_H
  8. #ifdef __cplusplus
  9. extern          "C" {
  10. #endif
  11. #define WILDCARDSTRING "*"
  12.     /*
  13.      * General.
  14.      */
  15. #define USM_MAX_ID_LENGTH 1024    /* In bytes. */
  16. #define USM_MAX_SALT_LENGTH 128     /* In BITS. */
  17. #define USM_DES_SALT_LENGTH 64      /* In BITS. */
  18. #define USM_AES_SALT_LENGTH 128     /* In BITS. */
  19. #define USM_MAX_KEYEDHASH_LENGTH 128     /* In BITS. */
  20. #define USM_TIME_WINDOW 150
  21. #define USM_MD5_AND_SHA_AUTH_LEN        12      /* bytes */
  22. #define USM_MAX_AUTHSIZE                USM_MD5_AND_SHA_AUTH_LEN
  23. #define USM_SEC_MODEL_NUMBER            3
  24.     /*
  25.      * Structures.
  26.      */
  27.     struct usmStateReference {
  28.         char           *usr_name;
  29.         size_t          usr_name_length;
  30.         u_char         *usr_engine_id;
  31.         size_t          usr_engine_id_length;
  32.         oid            *usr_auth_protocol;
  33.         size_t          usr_auth_protocol_length;
  34.         u_char         *usr_auth_key;
  35.         size_t          usr_auth_key_length;
  36.         oid            *usr_priv_protocol;
  37.         size_t          usr_priv_protocol_length;
  38.         u_char         *usr_priv_key;
  39.         size_t          usr_priv_key_length;
  40.         u_int           usr_sec_level;
  41.     };
  42.     /*
  43.      * struct usmUser: a structure to represent a given user in a list 
  44.      */
  45.     /*
  46.      * Note: Any changes made to this structure need to be reflected in
  47.      * the following functions: 
  48.      */
  49.     struct usmUser;
  50.     struct usmUser {
  51.         u_char         *engineID;
  52.         size_t          engineIDLen;
  53.         char           *name;
  54.         char           *secName;
  55.         oid            *cloneFrom;
  56.         size_t          cloneFromLen;
  57.         oid            *authProtocol;
  58.         size_t          authProtocolLen;
  59.         u_char         *authKey;
  60.         size_t          authKeyLen;
  61.         oid            *privProtocol;
  62.         size_t          privProtocolLen;
  63.         u_char         *privKey;
  64.         size_t          privKeyLen;
  65.         u_char         *userPublicString;
  66.         int             userStatus;
  67.         int             userStorageType;
  68.        /* these are actually DH * pointers but only if openssl is avail. */
  69.         void           *usmDHUserAuthKeyChange;
  70.         void           *usmDHUserPrivKeyChange;
  71.         struct usmUser *next;
  72.         struct usmUser *prev;
  73.     };
  74.     /*
  75.      * Prototypes.
  76.      */
  77.     struct usmStateReference *usm_malloc_usmStateReference(void);
  78.     void            usm_free_usmStateReference(void *old);
  79.     int             usm_set_usmStateReference_name(struct usmStateReference
  80.                                                    *ref, char *name,
  81.                                                    size_t name_len);
  82.     int             usm_set_usmStateReference_engine_id(struct
  83.                                                         usmStateReference
  84.                                                         *ref,
  85.                                                         u_char * engine_id,
  86.                                                         size_t
  87.                                                         engine_id_len);
  88.     int             usm_set_usmStateReference_auth_protocol(struct
  89.                                                             usmStateReference
  90.                                                             *ref,
  91.                                                             oid *
  92.                                                             auth_protocol,
  93.                                                             size_t
  94.                                                             auth_protocol_len);
  95.     int             usm_set_usmStateReference_auth_key(struct
  96.                                                        usmStateReference
  97.                                                        *ref,
  98.                                                        u_char * auth_key,
  99.                                                        size_t
  100.                                                        auth_key_len);
  101.     int             usm_set_usmStateReference_priv_protocol(struct
  102.                                                             usmStateReference
  103.                                                             *ref,
  104.                                                             oid *
  105.                                                             priv_protocol,
  106.                                                             size_t
  107.                                                             priv_protocol_len);
  108.     int             usm_set_usmStateReference_priv_key(struct
  109.                                                        usmStateReference
  110.                                                        *ref,
  111.                                                        u_char * priv_key,
  112.                                                        size_t
  113.                                                        priv_key_len);
  114.     int             usm_set_usmStateReference_sec_level(struct
  115.                                                         usmStateReference
  116.                                                         *ref,
  117.                                                         int sec_level);
  118. #ifdef SNMP_TESTING_CODE
  119.     void            emergency_print(u_char * field, u_int length);
  120. #endif
  121.     int             asn_predict_int_length(int type, long number,
  122.                                            size_t len);
  123.     int             asn_predict_length(int type, u_char * ptr,
  124.                                        size_t u_char_len);
  125.     int             usm_set_salt(u_char * iv,
  126.                                  size_t * iv_length,
  127.                                  u_char * priv_salt,
  128.                                  size_t priv_salt_length,
  129.                                  u_char * msgSalt);
  130.     int             usm_parse_security_parameters(u_char * secParams,
  131.                                                   size_t remaining,
  132.                                                   u_char * secEngineID,
  133.                                                   size_t * secEngineIDLen,
  134.                                                   u_int * boots_uint,
  135.                                                   u_int * time_uint,
  136.                                                   char *secName,
  137.                                                   size_t * secNameLen,
  138.                                                   u_char * signature,
  139.                                                   size_t *
  140.                                                   signature_length,
  141.                                                   u_char * salt,
  142.                                                   size_t * salt_length,
  143.                                                   u_char ** data_ptr);
  144.     int             usm_check_and_update_timeliness(u_char * secEngineID,
  145.                                                     size_t secEngineIDLen,
  146.                                                     u_int boots_uint,
  147.                                                     u_int time_uint,
  148.                                                     int *error);
  149.     SecmodOutMsg    usm_secmod_generate_out_msg;
  150.     SecmodOutMsg    usm_secmod_generate_out_msg;
  151.     SecmodInMsg     usm_secmod_process_in_msg;
  152.     int             usm_generate_out_msg(int, u_char *, size_t, int, int,
  153.                                          u_char *, size_t, char *, size_t,
  154.                                          int, u_char *, size_t, void *,
  155.                                          u_char *, size_t *, u_char **,
  156.                                          size_t *);
  157.     int             usm_rgenerate_out_msg(int, u_char *, size_t, int, int,
  158.                                           u_char *, size_t, char *, size_t,
  159.                                           int, u_char *, size_t, void *,
  160.                                           u_char **, size_t *, size_t *);
  161.     int             usm_process_in_msg(int, size_t, u_char *, int, int,
  162.                                        u_char *, size_t, u_char *,
  163.                                        size_t *, char *, size_t *,
  164.                                        u_char **, size_t *, size_t *,
  165.                                        void **, netsnmp_session *, u_char);
  166.     int             usm_check_secLevel(int level, struct usmUser *user);
  167.     struct usmUser *usm_get_userList(void);
  168.     struct usmUser *usm_get_user(u_char * engineID, size_t engineIDLen,
  169.                                  char *name);
  170.     struct usmUser *usm_get_user_from_list(u_char * engineID,
  171.                                            size_t engineIDLen, char *name,
  172.                                            struct usmUser *userList,
  173.                                            int use_default);
  174.     struct usmUser *usm_add_user(struct usmUser *user);
  175.     struct usmUser *usm_add_user_to_list(struct usmUser *user,
  176.                                          struct usmUser *userList);
  177.     struct usmUser *usm_free_user(struct usmUser *user);
  178.     struct usmUser *usm_create_user(void);
  179.     struct usmUser *usm_create_initial_user(const char *name,
  180.                                             const oid * authProtocol,
  181.                                             size_t authProtocolLen,
  182.                                             const oid * privProtocol,
  183.                                             size_t privProtocolLen);
  184.     struct usmUser *usm_cloneFrom_user(struct usmUser *from,
  185.                                        struct usmUser *to);
  186.     struct usmUser *usm_remove_user(struct usmUser *user);
  187.     struct usmUser *usm_remove_user_from_list(struct usmUser *user,
  188.                                               struct usmUser **userList);
  189.     char           *get_objid(char *line, oid ** optr, size_t * len);
  190.     void            usm_save_users(const char *token, const char *type);
  191.     void            usm_save_users_from_list(struct usmUser *user,
  192.                                              const char *token,
  193.                                              const char *type);
  194.     void            usm_save_user(struct usmUser *user, const char *token,
  195.                                   const char *type);
  196.     SNMPCallback    usm_store_users;
  197.     struct usmUser *usm_read_user(char *line);
  198.     void            usm_parse_config_usmUser(const char *token,
  199.                                              char *line);
  200.     void            usm_set_password(const char *token, char *line);
  201.     void            usm_set_user_password(struct usmUser *user,
  202.                                           const char *token, char *line);
  203.     void            init_usm(void);
  204.     void            init_usm_conf(const char *app);
  205.     int             init_usm_post_config(int majorid, int minorid,
  206.                                          void *serverarg, void *clientarg);
  207.     int             deinit_usm_post_config(int majorid, int minorid, void *serverarg,
  208.    void *clientarg);
  209.     void            clear_user_list(void);
  210. #ifdef __cplusplus
  211. }
  212. #endif
  213. #endif                          /* SNMPUSM_H */