📄 namingscopes.c
字号:
tmpViewString = (char *) SNMP_memory_alloc (EBufferUsed (¤t->commOrCon) +1); snprintf (tmpViewString, EBufferUsed (¤t->commOrCon) +1, "%s", EBufferStart (¤t->commOrCon)); printf ("Removing %s view\n", tmpViewString); SNMP_memory_free (tmpViewString);#endif /* NAMING_SCOPE_DEBUG */ if (previous == NULL) viewListHead->first = current->next; else previous->next = current->next; currentNext = current->next; if (current == *lastMatch) *lastMatch = NULL; EBufferClean (¤t->viewName); EBufferClean (¤t->commOrCon); SNMP_memory_free (current); } else { currentNext = current->next; previous = current; } } return (OK); } /* Not reached */ return (ERROR); }/****************************************************************************** * * viewFindIntern - Internal function to find a valid view * * This function searches for <commOrCon> with <viewType> in <viewListHead>, * which is either the list of valid community strings or context names. If * a match is found the view name for that view is returned at <viewName> * otherwise -1 is returned to indicate that the view is not in the list * or cannot be retrieved. * * Parameters: * * <viewListHead> - view list head * <commOrCon> - either community or context * <viewType> - view type to search for, get or set * <viewName> - view name to be returned if <commOrCon> found * * RETURNS: * * VS number if view found otherwise -1 * * viewName will also contain the view name if a view is found. * */LOCAL bits32_t viewFindIntern ( VIEW_LIST_HEAD_T viewListHead, EBUFFER_T commOrCon, bits8_t viewType, EBUFFER_T * viewName ) { VIEW_LIST_T * current, ** lastMatch = NULL; char * commOrConString; int stringLen; BOOL viewFound = FALSE;#if NAMING_SCOPE_DEBUG char * debugString;#endif /* NAMING_SCOPE_DEBUG */ stringLen = EBufferUsed (&commOrCon); commOrConString = (char *) EBufferStart (&commOrCon);#if NAMING_SCOPE_DEBUG debugString = (char *) SNMP_memory_alloc (stringLen+1); snprintf (debugString, stringLen+1, "%s", commOrConString);#endif /* NAMING_SCOPE_DEBUG */ if (viewListHead.listType == COMMUNITY_LIST) { lastMatch = &communityStringLastMatch;#if NAMING_SCOPE_DEBUG printf ("Search communities for %s\n", debugString);#endif /* NAMING_SCOPE_DEBUG */ }#if INSTALL_ENVOY_SNMP_VERSION_3 else if (viewListHead.listType == CONTEXT_LIST) { lastMatch = &contextNameLastMatch;#if NAMING_SCOPE_DEBUG printf ("Search contexts for %s\n", debugString);#endif /* NAMING_SCOPE_DEBUG */ }#endif /* INSTALL_ENVOY_SNMP_VERSION_3 */ else {#if NAMING_SCOPE_DEBUG printf ("\nUnknown list type!\n"); SNMP_memory_free (debugString);#endif /* NAMING_SCOPE_DEBUG */ return (-1); } /* * check the last match first as SNMP requests can be grouped, e.g. * for walking a table. */ if ((*lastMatch != NULL) && (((*lastMatch)->viewType & viewType) != 0) && (stringLen == EBufferUsed (&(*lastMatch)->commOrCon)) && (memcmp (commOrConString, EBufferStart (&(*lastMatch)->commOrCon), stringLen) == 0)) {#if NAMING_SCOPE_DEBUG printf ("Found view using the last match\n");#endif /* NAMING_SCOPE_DEBUG */ viewFound = TRUE; } /* No luck with the last match so start at the beginning of the list */#if NAMING_SCOPE_DEBUG if (!viewFound) printf ("%s was not the last match, searching entire list\n", debugString);#endif /* NAMING_SCOPE_DEBUG */ for (current = viewListHead.first; (current != NULL) && !viewFound; current = current->next) { /* Already checked the last match, don't do it again */ if (current == *lastMatch) continue; if (((current->viewType & viewType) != 0) && (stringLen == EBufferUsed (¤t->commOrCon)) && (memcmp (commOrConString, EBufferStart (¤t->commOrCon), stringLen) == 0)) {#if NAMING_SCOPE_DEBUG printf ("Found %s view!\n", debugString);#endif /* NAMING_SCOPE_DEBUG */ *lastMatch = current; viewFound = TRUE; } }#if NAMING_SCOPE_DEBUG SNMP_memory_free (debugString);#endif /* NAMING_SCOPE_DEBUG */ if (viewFound) { /* found existing view with correct viewType */ if ((viewName != NULL ) && ((EBufferClone (&(*lastMatch)->viewName, viewName)) != 0)) { /* error copying the returned EBuffer */ return (-1); } /* return vsNum if multi instance otherwise return 0 */ return ((*lastMatch)->vsNum); } else {#if NAMING_SCOPE_DEBUG printf ("view not found!\n");#endif /* NAMING_SCOPE_DEBUG */ return (-1); } }/* SNMPv1 + v2 Community String functions *//****************************************************************************** * * defaultCommunityStringsRegister - function to register default communities * * This function is an example of the function that can be called when this * module gets initialised. In envoy.h there is a #define for * DEFAULT_COMMUNITIES_REGISTER that, by default gets defined to this function. * If the user does not want or need the default communities added in this * function when this module is used then DEFAULT_COMMUNITIES_REGISTER must be * defined to a user function or NULL for no default communities. * * Parameters: * * <defaultVsNum> - the vsnum of VS to use for the default community strings * * RETURNS: N/A * */void defaultCommunityStringsRegister ( bits32_t defaultVsNum ) { communityStringRegister ((bits8_t *) "pub", 3, VIEW_TYPE_GET, (bits8_t *) "two", 3, defaultVsNum); communityStringRegister ((bits8_t *) "public", 6, VIEW_TYPE_GET, (bits8_t *) "two", 3, defaultVsNum); communityStringRegister ((bits8_t *) "icmp", 4, VIEW_TYPE_GET, (bits8_t *) "two", 3, defaultVsNum); communityStringRegister ((bits8_t *) "priv", 4, VIEW_TYPE_GET | VIEW_TYPE_SET, (bits8_t *) "two", 3, defaultVsNum); communityStringRegister ((bits8_t *) "private", 7, VIEW_TYPE_GET | VIEW_TYPE_SET, (bits8_t *) "two", 3, defaultVsNum); }/****************************************************************************** * * communityStringInit - Initialisation function for community string functions * * This function must be called before any other of the community string * functions in this file are called. This function initialises the list * of community strings and calls a function pointer to add the default * community strings if the function pointer has been initialised. * * Parameters: * * <defaultVsNum> - the vsnum of VS to use for the default community strings * * RETURNS: N/A * */void communityStringInit ( bits32_t defaultVsNum ) { communityStringHead.first = NULL; communityStringHead.listType = COMMUNITY_LIST; communityStringLastMatch = NULL; /* register the default community strings */ DEFAULT_COMMUNITIES_REGISTER (defaultVsNum); }/****************************************************************************** * * communityStringRegister - Register a community string * * This function will be called when a new community string is to be added * to the list of acceptable community strings. This function passes it's * parameters to the internal registration function along with the head of * the community strings list. * * Parameters: * * <newCommunityString> - the new community string to register * <stringLen> - the length of <newCommunityString> * <viewType> - type of view, get, set, get/set * <viewName> - view name for this community string * <indexLen> - the length of <viewName> * <vsNum> - the vsnum for the new community string * * RETURNS: return value from viewRegisterIntern * */STATUS communityStringRegister ( bits8_t * newCommunityString, bits32_t stringLen, bits8_t viewType, bits8_t * viewName, bits32_t indexLen, bits32_t vsNum ) { return (viewRegisterIntern (&communityStringHead, newCommunityString, stringLen, viewType, viewName, indexLen, vsNum)); }/****************************************************************************** * * communityStringDeregister - Deregister a community string * * This function will be called when a community string is to be removed * from the list of acceptable community strings. This function passes it's * parameters to the internal deregistration function along with the head of * the community strings list. * * Parameters: * * <communityString> - the community string to deregister * <stringLen> - the length of <communityString> * <viewType> - type of view to deregister, get, set, get/set * <vsNum> - the vsnum associated with <communityString> * * RETURNS: return value from viewDeregisterIntern * */STATUS communityStringDeregister ( bits8_t * communityString, bits32_t stringLen, bits8_t viewType, bits32_t vsNum ) { return (viewDeregisterIntern (&communityStringHead, communityString, stringLen, viewType, vsNum)); }/****************************************************************************** * * communityStringFind - Search for a valid community * * This function will be called to find a valid community string from * the list of acceptable community strings. This function passes it's * parameters to the internal search function along with the head of * the community strings list. *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -