Example #1
0
static int
_insert_nsfile( netsnmp_container *c, const char *name, struct stat *stats,
                u_int flags)
{
    int           rc;
    netsnmp_file *ns_file = netsnmp_file_new(name, 0, 0, 0);
    if (NULL == ns_file) {
        snmp_log(LOG_ERR, "error creating ns_file\n");
        return -1;
    }

    if (flags & NETSNMP_DIR_NSFILE_STATS) {
        ns_file->stats = (struct stat*)calloc(1,sizeof(*(ns_file->stats)));
        if (NULL == ns_file->stats) {
            snmp_log(LOG_ERR, "error creating stats for ns_file\n");
            netsnmp_file_release(ns_file);
            return -1;
        }
    
        /** use stats from earlier if we have them */
        if (stats)
            memcpy(ns_file->stats, stats, sizeof(*stats));
        else
            stat(ns_file->name, ns_file->stats);
    }

    rc = CONTAINER_INSERT(c, ns_file);
    if (-1 == rc ) {
        DEBUGMSGTL(("directory:container", "  err adding %s\n", name));
        netsnmp_file_release(ns_file);
    }

    return 0;
}
Example #2
0
netsnmp_container *
netsnmp_text_token_container_from_file(const char *file, u_int flags,
                                       netsnmp_container *cin, void *context)
{
    netsnmp_line_process_info  lpi;
    netsnmp_container         *c = cin, *c_rc;
    netsnmp_file              *fp;

    if (NULL == file)
        return NULL;

    /*
     * allocate file resources
     */
    fp = netsnmp_file_fill(NULL, file, O_RDONLY, 0, 0);
    if (NULL == fp) /** msg already logged */
        return NULL;

    memset(&lpi, 0x0, sizeof(lpi));
    lpi.mem_size = sizeof(netsnmp_token_value_index);
    lpi.process = _process_line_tvi;
    lpi.user_context = context;

    if (NULL == c) {
        c = netsnmp_container_find("string:binary_array");
        if (NULL == c) {
            snmp_log(LOG_ERR,"malloc failed\n");
            netsnmp_file_release(fp);
            return NULL;
        }
    }

    c_rc = netsnmp_file_text_parse(fp, c, PM_USER_FUNCTION, 0, &lpi);

    /*
     * if we got a bad return and the user didn't pass us a container,
     * we need to release the container we allocated.
     */
    if ((NULL == c_rc) && (NULL == cin)) {
        CONTAINER_FREE(c);
        c = NULL;
    }
    else
        c = c_rc;

    /*
     * release file resources
     */
    netsnmp_file_release(fp);
    
    return c;
}
/**
 *
 * @retval  0 no errors
 * @retval !0 errors
 */
static int
_load6(netsnmp_container *container, u_int load_flags)
{
    netsnmp_file              *fp;
    netsnmp_line_process_info  lpi;

    if (NULL == container)
        return -1;

    /*
     * allocate file resources
     */
    fp = netsnmp_file_fill(NULL, "/proc/net/udp6" , O_RDONLY, 0, 0);
    if (NULL == fp) /** msg already logged */
        return -2;
    
    memset(&lpi, 0x0, sizeof(lpi));
    lpi.mem_size = sizeof(netsnmp_udp_endpoint_entry);
    lpi.process = _process_line_udp_ep;
    lpi.user_context = (void*)CONTAINER_SIZE(container);

    container = netsnmp_file_text_parse(fp, container, PM_USER_FUNCTION,
                                        0, &lpi);
    netsnmp_file_release(fp);
    return (NULL == container);
}
Example #4
0
void
netsnmp_file_container_free(netsnmp_file *file, void *context)
{
    netsnmp_file_release(file);
}