Example #1
0
File: disk.c Project: 274914765/C
static void disk_parse_config_all (const char *token, char *cptr)
{
#if HAVE_FSTAB_H || HAVE_GETMNTENT || HAVE_STATFS
    int minpercent = DISKMINPERCENT;

    if (numdisks == maxdisks)
    {
        if (maxdisks == 0)
        {
            maxdisks = 50;
            disks = (struct diskpart *) malloc (maxdisks * sizeof (struct diskpart));
            if (!disks)
            {
                config_perror ("malloc failed for new disk allocation.");
                netsnmp_config_error ("\tignoring:  %s", cptr);
                return;
            }
            memset (disks, 0, maxdisks * sizeof (struct diskpart));
        }
        else
        {
            maxdisks *= 2;
            disks = (struct diskpart *) realloc (disks, maxdisks * sizeof (struct diskpart));
            if (!disks)
            {
                config_perror ("malloc failed for new disk allocation.");
                netsnmp_config_error ("\tignoring:  %s", cptr);
                return;
            }
            memset (disks + maxdisks / 2, 0, maxdisks / 2 * sizeof (struct diskpart));
        }
    }
    /*
     * read the minimum disk usage percent
     */
    if (cptr != NULL)
    {
        if (strchr (cptr, '%') != NULL)
        {
            minpercent = atoi (cptr);
        }
    }
    /*
     * if we have already seen the "includeAllDisks" directive
     * then search for the disk in the "disks" array and modify
     * the values. if we havent seen the "includeAllDisks"
     * directive then include this disk
     */
    if (allDisksIncluded)
    {
        config_perror ("includeAllDisks already specified.");
        netsnmp_config_error ("\tignoring: includeAllDisks %s", cptr);
    }
    else
    {
        allDisksIncluded = 1;
        find_and_add_allDisks (minpercent);
    }
#endif                            /* HAVE_FSTAB_H || HAVE_GETMNTENT || HAVE_STATFS */
}
Example #2
0
static void
system_parse_config_string2(const char *token, char *cptr,
                            char* value, size_t size)
{
    if (strlen(cptr) < size) {
        strcpy(value, cptr);
    } else {
        netsnmp_config_error("%s token too long (must be < %lu):\n\t%s",
                             token, (unsigned long)size, cptr);
    }
}
Example #3
0
void
netsnmp_parse_iquerySecLevel(const char *token, char *line)
{
    int secLevel;

    if ((secLevel = parse_secLevel_conf( token, line )) >= 0 ) {
        netsnmp_ds_set_int(NETSNMP_DS_APPLICATION_ID,
                           NETSNMP_DS_AGENT_INTERNAL_SECLEVEL, secLevel);
    } else {
	netsnmp_config_error("Unknown security level: %s", line);
    }
}
static void
system_parse_config_sysdescr(const char *token, char *cptr)
{
    if (strlen(cptr) >= sizeof(version_descr)) {
	netsnmp_config_error("sysdescr token too long (must be < %lu):\n\t%s",
			     (unsigned long)sizeof(version_descr), cptr);
    } else if (strcmp(cptr, "\"\"") == 0) {
        version_descr[0] = '\0';
    } else {
        strcpy(version_descr, cptr);
    }
}
static void
system_parse_config_sysObjectID(const char *token, char *cptr)
{
    size_t sysObjectIDLength = MAX_OID_LEN;
    if (!read_objid(cptr, sysObjectID, &sysObjectIDLength)) {
	netsnmp_config_error("sysobjectid token not a parsable OID:\n\t%s",
			     cptr);
        sysObjectIDByteLength = version_sysoid_len  * sizeof(oid);
        memcpy(sysObjectID, version_sysoid, sysObjectIDByteLength);
    } else
        sysObjectIDByteLength = sysObjectIDLength * sizeof(oid);
}
Example #6
0
/*
 * exactEngineID_conf(const char *, char *):
 * 
 * Reads a octet string encoded engineID into the engineID and
 * engineIDLen pointers.
 */
void
exactEngineID_conf(const char *word, char *cptr)
{
    read_config_read_octet_string(cptr, &engineID, &engineIDLength);
    if (engineIDLength > MAX_ENGINEID_LENGTH) {
	netsnmp_config_error(
	    "exactEngineID '%s' too long; truncating to %d bytes",
	    cptr, MAX_ENGINEID_LENGTH);
        engineID[MAX_ENGINEID_LENGTH - 1] = '\0';
        engineIDLength = MAX_ENGINEID_LENGTH;
    }
    engineIDIsSet = 1;
    engineIDType = ENGINEID_TYPE_EXACT;
}
Example #7
0
void
snmpv3_secLevel_conf(const char *word, char *cptr)
{
    int             secLevel;

    if ((secLevel = parse_secLevel_conf( word, cptr )) >= 0 ) {
        netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID, 
			   NETSNMP_DS_LIB_SECLEVEL, secLevel);
    } else {
	netsnmp_config_error("Unknown security level: %s", cptr);
    }
    DEBUGMSGTL(("snmpv3", "default secLevel set to: %s = %d\n", cptr,
                netsnmp_ds_get_int(NETSNMP_DS_LIBRARY_ID, 
				   NETSNMP_DS_LIB_SECLEVEL)));
}
void
snmpd_parse_config_informsink(const char *word, char *cptr)
{
    char           *st, *sp, *cp, *pp = NULL;

    if (!snmp_trapcommunity)
        snmp_trapcommunity = strdup("public");
    sp = strtok_r(cptr, " \t\n", &st);
    cp = strtok_r(NULL, " \t\n", &st);
    if (cp)
        pp = strtok_r(NULL, " \t\n", &st);
    if (pp)
	config_pwarn("The separate port argument to informsink is deprecated");
    if (create_v2_inform_session(sp, pp, cp ? cp : snmp_trapcommunity) == 0) {
	netsnmp_config_error("cannot create informsink: %s", cptr);
    }
}
NETSNMP_STATIC_INLINE void
system_parse_config_string(const char *token, char *cptr,
                           const char *name, char* value, size_t size,
                           int* guard)
{
    if (strlen(cptr) >= size) {
	netsnmp_config_error("%s token too long (must be < %lu):\n\t%s",
			     token, (unsigned long)size, cptr);
    }

    if (*token == 'p' && strcasecmp(token + 1, name) == 0) {
        if (*guard < 0) {
            /*
             * This is bogus (and shouldn't happen anyway) -- the value is
             * already configured read-only.
             */
            snmp_log(LOG_WARNING,
                     "ignoring attempted override of read-only %s.0\n", name);
            return;
        } else {
            ++(*guard);
        }
    } else {
        if (*guard > 0) {
            /*
             * This is bogus (and shouldn't happen anyway) -- we already read a
             * persistent value which we should ignore in favour of this one.
             */
            snmp_log(LOG_WARNING,
                     "ignoring attempted override of read-only %s.0\n", name);
            /*
             * Fall through and copy in this value.
             */
        }
        *guard = -1;
    }

    if (strcmp(cptr, "\"\"") == 0) {
        *value = '\0';
    } else if (strlen(cptr) < size) {
        strcpy(value, cptr);
    }
}
Example #10
0
void agentx_parse_master (const char *token, char *cptr)
{
    int i = -1;

    if (!strcmp (cptr, "agentx") || !strcmp (cptr, "all") || !strcmp (cptr, "yes") || !strcmp (cptr, "on"))
    {
        i = 1;
        snmp_log (LOG_INFO, "Turning on AgentX master support.\n");
    }
    else if (!strcmp (cptr, "no") || !strcmp (cptr, "off"))
        i = 0;
    else
        i = atoi (cptr);

    if (i < 0 || i > 1)
    {
        netsnmp_config_error ("master '%s' unrecognised", cptr);
    }
    else
        netsnmp_ds_set_boolean (NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_AGENTX_MASTER, i);
}
Example #11
0
void
netsnmp_parse_iqueryVersion(const char *token, char *line)
{
#ifndef NETSNMP_DISABLE_SNMPV1
    if (!strcmp( line, "1" ))
        netsnmp_ds_set_int(NETSNMP_DS_APPLICATION_ID,
                           NETSNMP_DS_AGENT_INTERNAL_VERSION, SNMP_VERSION_1);
    else 
#endif
#ifndef NETSNMP_DISABLE_SNMPV2C
         if (!strcmp( line, "2"  ) || !strcasecmp( line, "2c" ))
        netsnmp_ds_set_int(NETSNMP_DS_APPLICATION_ID,
                           NETSNMP_DS_AGENT_INTERNAL_VERSION, SNMP_VERSION_2c);
    else 
#endif
         if (!strcmp( line, "3" ))
        netsnmp_ds_set_int(NETSNMP_DS_APPLICATION_ID,
                           NETSNMP_DS_AGENT_INTERNAL_VERSION, SNMP_VERSION_3);
    else {
	netsnmp_config_error("Unknown version: %s", line);
    }
}
static void
_parse_mib_maps(const char *token, char *line)
{
    netsnmp_tdata_row *row;
    certToTSN_entry   *entry;
    netsnmp_cert_map *map = netsnmp_certToTSN_parse_common(&line);

    if (NULL == line) {
        netsnmp_config_error("incomplete line");
        netsnmp_cert_map_free(map);
        return;
    }

    map->flags = NSCM_FROM_MIB | NSCM_NONVOLATILE;
    row = _entry_from_map(map);
    if (NULL == row) {
        netsnmp_cert_map_free(map);
        return;
    }
    
    entry = (certToTSN_entry*)row->data;
    entry->rowStatus = atoi(line);
    entry->storageType = ST_NONVOLATILE;

    /*
     * if row is active, add it to the maps container so it is available
     * for use. Do not add it to the table, since it will be added
     * during cache_load.
     */
    if (RS_ACTIVE == entry->rowStatus) {
        if (netsnmp_cert_map_add(map) != 0)
            netsnmp_cert_map_free(map);
    }
    else {
        netsnmp_cert_map_free(map);
        if (netsnmp_tdata_add_row(_table, row) != SNMPERR_SUCCESS)
            tlstmCertToTSNTable_removeEntry(NULL, row);
    }
}
Example #13
0
void
snmptrapd_parse_traphandle(const char *token, char *line)
{
    char            buf[STRINGMAX];
    oid             obuf[MAX_OID_LEN];
    size_t          olen = MAX_OID_LEN;
    char           *cptr, *cp;
    netsnmp_trapd_handler *traph;
    int             flags = 0;
    char           *format = NULL;

    memset( buf, 0, sizeof(buf));
    memset(obuf, 0, sizeof(obuf));
    cptr = copy_nword(line, buf, sizeof(buf));

    if ( buf[0] == '-' && buf[1] == 'F' ) {
        cptr = copy_nword(cptr, buf, sizeof(buf));
        format = strdup( buf );
        cptr = copy_nword(cptr, buf, sizeof(buf));
    }
    if ( !cptr ) {
        netsnmp_config_error("Missing traphandle command (%s)", buf);
        return;
    }

    DEBUGMSGTL(("read_config:traphandle", "registering handler for: "));
    if (!strcmp(buf, "default")) {
        DEBUGMSG(("read_config:traphandle", "default"));
        traph = netsnmp_add_global_traphandler(NETSNMPTRAPD_DEFAULT_HANDLER,
                                               command_handler );
    } else {
        cp = buf+strlen(buf)-1;
        if ( *cp == '*' ) {
            flags |= NETSNMP_TRAPHANDLER_FLAG_MATCH_TREE;
            *(cp--) = '\0';
            if ( *cp == '.' ) {
                /* 
                 * Distinguish between 'oid.*' & 'oid*'
                 */
                flags |= NETSNMP_TRAPHANDLER_FLAG_STRICT_SUBTREE;
                *(cp--) = '\0';
            }
        }
        if (!read_objid(buf, obuf, &olen)) {
	    netsnmp_config_error("Bad trap OID in traphandle directive: %s",
				 buf);
            return;
        }
        DEBUGMSGOID(("read_config:traphandle", obuf, olen));
        traph = netsnmp_add_traphandler( command_handler, obuf, olen );
    }

    DEBUGMSG(("read_config:traphandle", "\n"));

    if (traph) {
        traph->flags = flags;
        traph->authtypes = TRAP_AUTH_EXE;
        traph->token = strdup(cptr);
        if (format)
            traph->format = format;
    }
}
Example #14
0
static void 
disk_parse_config(const char *token, char *cptr)
{
#if HAVE_FSTAB_H || HAVE_GETMNTENT || HAVE_STATFS
  char            path[STRMAX];
  int             minpercent;
  int             minspace;

  if (numdisks == maxdisks) {
      if (maxdisks == 0) {
          maxdisks = 50;
          disks = (struct diskpart *)malloc(maxdisks * sizeof(struct diskpart));
          if (!disks) {
              config_perror("malloc failed for new disk allocation.");
	      netsnmp_config_error("\tignoring:  %s", cptr);
              return;
          }
          memset(disks, 0, maxdisks * sizeof(struct diskpart));
      } else {
          maxdisks *= 2;
          disks = (struct diskpart *)realloc(disks, maxdisks * sizeof(struct diskpart));
          if (!disks) {
              config_perror("malloc failed for new disk allocation.");
	      netsnmp_config_error("\tignoring:  %s", cptr);
              return;
          }
          memset(disks + maxdisks/2, 0, maxdisks/2 * sizeof(struct diskpart));
      }
  }

  /*
   * read disk path (eg, /1 or /usr) 
   */
  copy_nword(cptr, path, sizeof(path));
  cptr = skip_not_white(cptr);
  cptr = skip_white(cptr);
	
  /*
   * read optional minimum disk usage spec 
   */
  if(cptr != NULL) {
      if(strchr(cptr, '%') == NULL) {
          minspace = atoi(cptr);
          minpercent = -1;
      }
      else {
          minspace = -1;
          minpercent = atoi(cptr);
      }
  } else {
      minspace = NETSNMP_DEFDISKMINIMUMSPACE;
      minpercent = -1;
  }

  /*
   * check if the disk already exists, if so then modify its
   * parameters. if it does not exist then add it
   */
  add_device(path, find_device(path), minspace, minpercent, 1);
#endif /* HAVE_FSTAB_H || HAVE_GETMNTENT || HAVE_STATFS */
}