00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include <sys/types.h>
00035
00036 #include <stdlib.h>
00037 #include <string.h>
00038
00039 #include <pro/snmp_config.h>
00040
00041 static VIEW_LIST *views;
00042 static COMMUNITY_LIST *communities;
00043
00050 int SnmpViewCreate(CONST char *name, CONST OID * subtree, size_t subtreelen, int type)
00051 {
00052 static int nextview = 1;
00053 VIEW_LIST *vp;
00054 VIEW_LIST *nvp;
00055 VIEW_LIST *prev = NULL;
00056 size_t i;
00057
00058
00059 if (strlen(name) > (sizeof(vp->view_name) - 1)) {
00060 return -1;
00061 }
00062
00063
00064 for (vp = views; vp; prev = vp, vp = vp->next) {
00065 if (strcmp(name, vp->view_name) == 0) {
00066 break;
00067 }
00068 }
00069
00070
00071 nvp = malloc(sizeof(VIEW_LIST));
00072 memset(nvp, 0, sizeof(VIEW_LIST));
00073 strcpy(nvp->view_name, name);
00074 nvp->view_type = type;
00075 nvp->view_subtree_len = subtreelen;
00076 for (i = 0; i < subtreelen; i++) {
00077 nvp->view_subtree[i] = subtree[i];
00078 }
00079
00080 nvp->view_index = vp ? vp->view_index : nextview++;
00081
00082
00083 if (views) {
00084 for (; vp; prev = vp, vp = vp->next);
00085 prev->next = nvp;
00086 } else {
00087 views = nvp;
00088 }
00089 return nvp->view_index;
00090 }
00091
00092 int SnmpViewFind(char *name)
00093 {
00094 VIEW_LIST *vp;
00095
00096 if (strcmp(name, "-") == 0) {
00097 return 0;
00098 }
00099 for (vp = views; vp; vp = vp->next) {
00100 if (strcmp(vp->view_name, name) == 0) {
00101 return vp->view_index;
00102 }
00103 }
00104 return -1;
00105 }
00106
00118 int SnmpCommunityFind(CONST char *name, int *readView, int *writeView)
00119 {
00120 COMMUNITY_LIST *cp;
00121
00122 for (cp = communities; cp; cp = cp->next) {
00123 if (strcmp(cp->comm_name, name) == 0) {
00124 if (readView) {
00125 *readView = cp->comm_read_view;
00126 }
00127 if (writeView) {
00128 *writeView = cp->comm_write_view;
00129 }
00130 return 0;
00131 }
00132 }
00133 return -1;
00134 }
00135
00147 int SnmpCommunityCreate(CONST char *name, int readView, int writeView)
00148 {
00149 COMMUNITY_LIST *cp;
00150 COMMUNITY_LIST *prev = 0;
00151
00152 if (strlen(name) > (sizeof(cp->comm_name) - 1)) {
00153 return -1;
00154 }
00155 for (cp = communities; cp; cp = cp->next) {
00156 if (strcmp(name, cp->comm_name) == 0) {
00157 return 0;
00158 }
00159 prev = cp;
00160 }
00161
00162 cp = malloc(sizeof(COMMUNITY_LIST));
00163 memset(cp, 0, sizeof(COMMUNITY_LIST));
00164 strcpy(cp->comm_name, name);
00165 cp->comm_read_view = readView;
00166 cp->comm_write_view = writeView;
00167 if (prev) {
00168 prev->next = cp;
00169 } else {
00170 communities = cp;
00171 }
00172 return 0;
00173 }