Beispiel #1
0
struct subtree *find_extensible(struct subtree	*tp,
				oid tname[],
				int tnamelen,
				int exact)
{
  int i,tmp;
  struct extensible *exten = 0;
  struct variable myvp;
  oid name[MAX_OID_LEN];
  static struct subtree mysubtree[2];

  for(i=1; i<= numrelocs; i++) {
    exten = get_exten_instance(relocs,i);
    if (exten->miblen != 0){
      memcpy(myvp.name,exten->miboid,exten->miblen*sizeof(oid));
      memcpy(name,tname,tnamelen*sizeof(oid));
      myvp.name[exten->miblen] = name[exten->miblen];
      myvp.namelen = exten->miblen+1;
      tmp = exten->miblen+1;
      if (!header_simple_table(&myvp,name,&tmp,-1,NULL,NULL, numrelocs))
        break;
    }
  }
  if (i > numrelocs || exten == NULL)
    return(tp);
  memcpy(mysubtree[0].name,exten->miboid,exten->miblen*sizeof(oid));
  mysubtree[0].namelen = exten->miblen;
  mysubtree[0].variables = (struct variable *)extensible_relocatable_variables;
  mysubtree[0].variables_len =
    sizeof(extensible_relocatable_variables)/sizeof(*extensible_relocatable_variables);
  mysubtree[0].variables_width = sizeof(*extensible_relocatable_variables);
  mysubtree[1].namelen = 0;
  return(mysubtree);
}
Beispiel #2
0
/*
 * var_dot3ControlTable():
 *   Handle this table separately from the scalar value case.
 *   The workings of this are basically the same as for var_dot3ControlTable above.
 */
unsigned char *
var_dot3ControlTable(struct variable *vp,
            oid     *name,
            size_t  *length,
            int     exact,
            size_t  *var_len,
            WriteMethod **write_method)
{
    /* variables we may use later */
    static long long_ret;
    static unsigned char string[SPRINT_MAX_LEN];
    static oid objid[MAX_OID_LEN];
    static struct counter64 c64;
    if (header_simple_table(vp,name,length,exact,var_len,write_method, TABLE_SIZE)
        == MATCH_FAILED )
        return NULL;

    switch(vp->magic) {
    case DOT3CONTROLFUNCTIONSSUPPORTED:
        long_ret = 1;
        return &long_ret;

    case DOT3CONTROLINUNKNOWNOPCODES:
        long_ret = 0;
        return (unsigned char *) &long_ret;

    default:
      ERROR_MSG("");
    }
    return NULL;
}
Beispiel #3
0
u_char         *
var_diskio(struct variable * vp,
           oid * name,
           size_t * length,
           int exact, size_t * var_len, WriteMethod ** write_method)
{
    static long     long_ret;
    static struct counter64 c64_ret;
    unsigned int    indx;

    /* get disk statistics */
    if (collect_disks())
        return NULL;

    if (header_simple_table
        (vp, name, length, exact, var_len, write_method, ps_numdisks))
        return NULL;

    indx = (unsigned int) (name[*length - 1] - 1);
    if (indx >= ps_numdisks)
        return NULL;

    /* deliver requested data on requested disk */
    switch (vp->magic) {
    case DISKIO_INDEX:
        long_ret = (long) indx;
        return (u_char *) & long_ret;
    case DISKIO_DEVICE:
        *var_len = strlen(ps_disk[indx].name);
        return (u_char *) ps_disk[indx].name;
    case DISKIO_NREAD:
        long_ret = (signed long) ps_disk[indx].rblks * ps_disk[indx].bsize;
        return (u_char *) & long_ret;
    case DISKIO_NWRITTEN:
        long_ret = (signed long) ps_disk[indx].wblks * ps_disk[indx].bsize;
        return (u_char *) & long_ret;
    case DISKIO_READS:
        long_ret = (signed long) ps_disk[indx].xfers;
        return (u_char *) & long_ret;
    case DISKIO_WRITES:
        long_ret = (signed long) 0;	/* AIX has just one value for read/write transfers */
        return (u_char *) & long_ret;
    case DISKIO_NREADX:
        *var_len = sizeof(struct counter64);
        c64_ret.low = (ps_disk[indx].rblks * ps_disk[indx].bsize) & 0xffffffff;;
        c64_ret.high = (ps_disk[indx].rblks * ps_disk[indx].bsize) >> 32;
        return (u_char *) & c64_ret;
    case DISKIO_NWRITTENX:
        *var_len = sizeof(struct counter64);
        c64_ret.low = (ps_disk[indx].wblks * ps_disk[indx].bsize) & 0xffffffff;;
        c64_ret.high = (ps_disk[indx].wblks * ps_disk[indx].bsize) >> 32;
        return (u_char *) & c64_ret;

    default:
        ERROR_MSG("diskio.c: don't know how to handle this request.");
    }

    /* return NULL in case of error */
    return NULL;
}
Beispiel #4
0
u_char *
var_diskio(struct variable * vp,
	   oid * name,
	   size_t * length,
	   int exact,
	   size_t * var_len,
	   WriteMethod ** write_method)
{
    unsigned int indx;
    static unsigned long long_ret;
    static struct counter64 c64_ret;

    if (getstats() == 1) {
	return NULL;
    }

 if (header_simple_table(vp, name, length, exact, var_len, write_method, head.length))
    {
	return NULL;
    }

  indx = (unsigned int) (name[*length - 1] - 1);

  if (indx >= head.length)
    return NULL;

  switch (vp->magic) {
    case DISKIO_INDEX:
      long_ret = indx+1;
      return (u_char *) &long_ret;
    case DISKIO_DEVICE:
      *var_len = strlen(head.indices[indx].name);
      return (u_char *) head.indices[indx].name;
    case DISKIO_NREAD:
      long_ret = (head.indices[indx].rsect*512) & 0xffffffff;
      return (u_char *) & long_ret;
    case DISKIO_NWRITTEN:
      long_ret = (head.indices[indx].wsect*512) & 0xffffffff;
      return (u_char *) & long_ret;
    case DISKIO_READS:
      long_ret = head.indices[indx].rio & 0xffffffff;
      return (u_char *) & long_ret;
    case DISKIO_WRITES:
      long_ret = head.indices[indx].wio & 0xffffffff;
      return (u_char *) & long_ret;
    case DISKIO_NREADX:
      *var_len = sizeof(struct counter64);
      c64_ret.low = head.indices[indx].rsect * 512 & 0xffffffff;
      c64_ret.high = head.indices[indx].rsect >> (32 - 9);
      return (u_char *) & c64_ret;
    case DISKIO_NWRITTENX:
      *var_len = sizeof(struct counter64);
      c64_ret.low = head.indices[indx].wsect * 512 & 0xffffffff;
      c64_ret.high = head.indices[indx].wsect >> (32 - 9);
      return (u_char *) & c64_ret;
    default:
	snmp_log(LOG_ERR, "don't know how to handle %d request\n", vp->magic);
  }
  return NULL;
}
Beispiel #5
0
/*
 * var_wapiApAlarmAdminTable():
 *   Handle this table separately from the scalar value case.
 *   The workings of this are basically the same as for var_wapiPwlanAp above.
 */
unsigned char *
var_wapiApAlarmAdminTable(struct variable *vp,
    	    oid     *name,
    	    size_t  *length,
    	    int     exact,
    	    size_t  *var_len,
    	    WriteMethod **write_method)
{

    /* variables we may use later */
    static long long_ret;
    static u_long ulong_ret;
    static unsigned char string[256];
    static oid objid[MAX_OID_LEN];
    int ret,i;
 
   if (header_simple_table(vp,name,length,exact,var_len,write_method, 1)
                                                == MATCH_FAILED )
    return NULL;
    for(i=0;i<name[*length-1];i++) {
    }
    memset(string,0,256);
    switch(vp->magic) {
    case ALARMID:
	*var_len=0;
        return (u_char*) string;
    case ALARMNAME:
	*var_len=0;
        return (u_char*) string;
    case ALARMLEVEL:
	*var_len=0;
        return (u_char*) string;
    case ALARMTYPE:
	*var_len=0;
        return (u_char*) string;
	case ALARMREASONID:
	long_ret=0;
        return (u_char*) &long_ret;
    case ALARMREASON:
	long_ret=0;
        return (u_char*) &long_ret;
    case ALARMCREATTIMES:
        long_ret=0;
        return (u_char*) &long_ret;
    case ALARMSTATE:
        long_ret=0;
        return (u_char*) &long_ret;
    case ALARMHEADING:
	*var_len=0;
        return (u_char*) string;
    case ALARMCONTENT:
	*var_len=0;
        return (u_char*) string;
    default:
      ERROR_MSG("");
    }
    return NULL;
}
unsigned char *
var_sensors_table(struct variable *vp, oid *name, size_t *length, int exact,
		size_t *var_len, WriteMethod **write_method)
{
	int index;
	struct sensor sensor;
	struct sensordev sdev;
	static u_long ulong_ret;
	static unsigned char str[BUFSIZ];

	sensor_refresh();

	if (num_sensors == 0)
		return (NULL);

	if (header_simple_table(vp, name, length, exact, var_len,
				write_method, num_sensors)
			== MATCH_FAILED)
		return (NULL);

	index = name[*length-1]-1;
	if (sensor_get(index, &sdev, &sensor))
		return (NULL);

	switch (vp->magic) {
		case SENS_INDEX:
			ulong_ret = name[*length-1];
			return (unsigned char *) &ulong_ret;
		case SENS_DESCR:
			sensor_desc(index, &sensor, str, BUFSIZ);
			*var_len = strlen(str);
			return (unsigned char *) str;
		case SENS_TYPE:
			ulong_ret = sensor.type;
			return (unsigned char *) &ulong_ret;
		case SENS_DEVICE:
			if ((*var_len = strlcpy(str, sdev.xname, BUFSIZ)) !=
					strlen(sdev.xname))
				return (NULL);
			return (unsigned char *) str;
		case SENS_VALUE:
			sensor_value(&sensor, str);
			*var_len = strlen(str);
			return (unsigned char *) str;
		case SENS_UNITS:
			sensor_units(&sensor, str);
			*var_len = strlen(str);
			return (unsigned char *) str;
		case SENS_STATUS:
			ulong_ret = sensor.status;
			return (unsigned char *) &ulong_ret;
		default:
			return (NULL);
	}
	
	/* NOTREACHED */
}
unsigned char *var_mgtCommunityTable(struct variable *vp,
                                    oid     *name,
                                    size_t  *length,
                                    int     exact,
                                    size_t  *var_len,
                                    WriteMethod **write_method)
{
    static long long_ret;
    //static unsigned char string[SPRINT_MAX_LEN];
		static char DBdata[64];
    char    idx;

		#ifdef TABLE_SIZE
		#undef TABLE_SIZE
		#endif
    #define TABLE_SIZE 2
    if (header_simple_table(vp,name,length,exact,var_len,write_method, TABLE_SIZE)
                                                            == MATCH_FAILED )
        return NULL;


    idx = name[*length-1];
    if (idx == 1)
    {
				kd_doCommand("SNMP GCNAME", CMD_PRINT, ASH_DO_NOTHING, DBdata);
        long_ret = 1;
    }
    else if (idx == 2)
    {
        kd_doCommand("SNMP SCNAME", CMD_PRINT, ASH_DO_NOTHING, DBdata);
        long_ret = 2;
    }
    else
        return NULL;


    /* this is where we do the value assignments for the mib results. */
    switch (vp->magic)
    {
        case MGTCOMMUNITYINDEX:
            long_ret = idx;
            return (unsigned char *) &long_ret;

        case MGTCOMMUNITYNAME:
						*write_method = write_mgtCommunityName;
						*var_len = strlen(DBdata);
						return (unsigned char *) DBdata;

        case MGTCOMMUNITYTYPE:
            *write_method = write_mgtCommunityType;
            return (unsigned char *) &long_ret;

        default:
            ERROR_MSG("");
    }
    return NULL;
}
Beispiel #8
0
u_char         *
var_diskio(struct variable * vp,
           oid * name,
           size_t * length,
           int exact, size_t * var_len, WriteMethod ** write_method)
{
    static long     long_ret;
    static struct counter64 c64_ret;
    unsigned int    indx;

    if (getstats() == 0)
        return 0;

    if (header_simple_table
        (vp, name, length, exact, var_len, write_method, ndisk))
        return NULL;

    indx = (unsigned int) (name[*length - 1] - 1);
    if (indx >= ndisk)
        return NULL;

    switch (vp->magic) {
    case DISKIO_INDEX:
        long_ret = (long) indx + 1;
        return (u_char *) & long_ret;
    case DISKIO_DEVICE:
        *var_len = strlen(dkname[indx]);
        return (u_char *) dkname[indx];
    case DISKIO_NREAD:
        long_ret = (unsigned long) (dk[indx].ds_rbytes) & 0xffffffff;
        return (u_char *) & long_ret;
    case DISKIO_NWRITTEN:
        long_ret = (unsigned long) (dk[indx].ds_wbytes) & 0xffffffff;
        return (u_char *) & long_ret;
    case DISKIO_READS:
        long_ret = (unsigned long) dk[indx].ds_rxfer & 0xffffffff;
        return (u_char *) & long_ret;
    case DISKIO_WRITES:
        long_ret = (unsigned long) dk[indx].ds_wxfer & 0xffffffff;
        return (u_char *) & long_ret;
    case DISKIO_NREADX:
        *var_len = sizeof(struct counter64);
        c64_ret.low = dk[indx].ds_rbytes & 0xffffffff;
        c64_ret.high = dk[indx].ds_rbytes >> 32;
        return (u_char *) & c64_ret;
    case DISKIO_NWRITTENX:
        *var_len = sizeof(struct counter64);
        c64_ret.low = dk[indx].ds_rbytes & 0xffffffff;
        c64_ret.high = dk[indx].ds_rbytes >> 32;
        return (u_char *) & c64_ret;

    default:
        ERROR_MSG("diskio.c: don't know how to handle this request.");
    }
    return NULL;
}
u_char *
var_sysORTable(struct variable *vp,
		oid *name,
		size_t *length,
		int exact,
		size_t *var_len,
		WriteMethod **write_method)
{
  struct timeval diff;
  int i;
  struct sysORTable *ptr;

  if (header_simple_table(vp, name, length, exact, var_len, write_method, numEntries))
    return NULL;

  DEBUGMSGTL(("mibII/sysORTable", "sysORTable -- "));
  for(i = 1, ptr=table; ptr != NULL && i < (int)name[*length-1];
      ptr = ptr->next, i++) {
    DEBUGMSGTL(("mibII/sysORTable", "sysORTable -- %d != %d\n",i,name[*length-1]));
  }
  if (ptr == NULL) {
    DEBUGMSGTL(("mibII/sysORTable", "sysORTable -- no match: %d\n",i));
    return NULL;
  }
  DEBUGMSGTL(("mibII/sysORTable", "sysORTable -- match: %d\n",i));
  
  switch (vp->magic){
    case SYSORTABLEID:
      *var_len = ptr->OR_oidlen*sizeof(ptr->OR_oid[0]);
      return (u_char *) ptr->OR_oid;

    case SYSORTABLEDESCR:
      *var_len = strlen(ptr->OR_descr);
      return (u_char *) ptr->OR_descr;

    case SYSORTABLEUPTIME:
      ptr->OR_uptime.tv_sec--;
      ptr->OR_uptime.tv_usec += 1000000L;
      diff.tv_sec = ptr->OR_uptime.tv_sec - 1 - starttime.tv_sec;
      diff.tv_usec = ptr->OR_uptime.tv_usec + 1000000L - starttime.tv_usec;
      if (diff.tv_usec > 1000000L){
        diff.tv_usec -= 1000000L;
        diff.tv_sec++;
      }
      if ((diff.tv_sec * 100) + (diff.tv_usec / 10000) < 0)
        long_return = 0;
      else
        long_return = ((diff.tv_sec * 100) + (diff.tv_usec / 10000));
      return ((u_char *) &long_return);

    default:
      DEBUGMSGTL(("snmpd", "unknown sub-id %d in var_sysORTable\n", vp->magic));
  }
  return NULL;
}
Beispiel #10
0
/*
 * checkmib(): provided for backwards compatibility, do not use: 
 */
int
checkmib (struct variable *vp, oid * name, size_t * length,
          int exact, size_t * var_len, WriteMethod ** write_method, int max)
{
    /*
     * checkmib used to be header_simple_table, with reveresed boolean
     * return output.  header_simple_table() was created to match
     * header_generic(). 
     */
    return (!header_simple_table (vp, name, length, exact, var_len, write_method, max));
}
Beispiel #11
0
static u_char *ast_var_indications_table(struct variable *vp, oid *name, size_t *length,
									   int exact, size_t *var_len, WriteMethod **write_method)
{
	static unsigned long long_ret;
	static char ret_buf[256];
	struct ast_tone_zone *tz = NULL;
	int i;
	struct ao2_iterator iter;

	if (header_simple_table(vp, name, length, exact, var_len, write_method, -1)) {
		return NULL;
	}

	i = name[*length - 1] - 1;

	iter = ast_tone_zone_iterator_init();

	while ((tz = ao2_iterator_next(&iter)) && i) {
		tz = ast_tone_zone_unref(tz);
		i--;
	}
	ao2_iterator_destroy(&iter);

	if (tz == NULL) {
		return NULL;
	}

	switch (vp->magic) {
	case ASTINDINDEX:
		ast_tone_zone_unref(tz);
		long_ret = name[*length - 1];
		return (u_char *)&long_ret;
	case ASTINDCOUNTRY:
		ast_copy_string(ret_buf, tz->country, sizeof(ret_buf));
		ast_tone_zone_unref(tz);
		*var_len = strlen(ret_buf);
		return (u_char *) ret_buf;
	case ASTINDALIAS:
		/* No longer exists */
		ast_tone_zone_unref(tz);
		return NULL;
	case ASTINDDESCRIPTION:
		ast_tone_zone_lock(tz);
		ast_copy_string(ret_buf, tz->description, sizeof(ret_buf));
		ast_tone_zone_unlock(tz);
		ast_tone_zone_unref(tz);
		*var_len = strlen(ret_buf);
		return (u_char *) ret_buf;
	default:
		ast_tone_zone_unref(tz);
		break;
	}
	return NULL;
}
Beispiel #12
0
static u_char *ast_var_channel_types_table(struct variable *vp, oid *name, size_t *length,
										int exact, size_t *var_len, WriteMethod **write_method)
{
	const struct ast_channel_tech *tech = NULL;
	struct ast_variable *channel_types, *next;
	static unsigned long long_ret;
	struct ast_channel *chan;
	u_long i;

	if (header_simple_table(vp, name, length, exact, var_len, write_method, -1))
		return NULL;

	channel_types = ast_channeltype_list();
	for (i = 1, next = channel_types; next && i != name[*length - 1]; next = next->next, i++)
		;
	if (next != NULL)
		tech = ast_get_channel_tech(next->name);
	ast_variables_destroy(channel_types);
	if (next == NULL || tech == NULL)
		return NULL;
	
	switch (vp->magic) {
	case ASTCHANTYPEINDEX:
		long_ret = name[*length - 1];
		return (u_char *)&long_ret;
	case ASTCHANTYPENAME:
		*var_len = strlen(tech->type);
		return (u_char *)tech->type;
	case ASTCHANTYPEDESC:
		*var_len = strlen(tech->description);
		return (u_char *)tech->description;
	case ASTCHANTYPEDEVSTATE:
		long_ret = tech->devicestate ? 1 : 2;
		return (u_char *)&long_ret;
	case ASTCHANTYPEINDICATIONS:
		long_ret = tech->indicate ? 1 : 2;
		return (u_char *)&long_ret;
	case ASTCHANTYPETRANSFER:
		long_ret = tech->transfer ? 1 : 2;
		return (u_char *)&long_ret;
	case ASTCHANTYPECHANNELS:
		long_ret = 0;
		for (chan = ast_channel_walk_locked(NULL); chan; chan = ast_channel_walk_locked(chan)) {
			if (chan->tech == tech)
				long_ret++;
			ast_channel_unlock(chan);
		}
		return (u_char *)&long_ret;
	default:
		break;
	}
	return NULL;
}
Beispiel #13
0
unsigned char *var_extensible_shell(struct variable *vp,
				    oid *name,
				    int *length,
				    int exact,
				    int *var_len,
				    WriteMethod **write_method)
{

  static struct extensible *exten = 0;
  static long long_ret;

  if (header_simple_table(vp,name,length,exact,var_len,write_method,numextens))
    return(NULL);

  if ((exten = get_exten_instance(extens,name[*length-1]))) {
    switch (vp->magic) {
      case MIBINDEX:
        long_ret = name[*length-1];
        return((u_char *) (&long_ret));
      case ERRORNAME: /* name defined in config file */
        *var_len = strlen(exten->name);
        return((u_char *) (exten->name));
      case SHELLCOMMAND:
        *var_len = strlen(exten->command);
        return((u_char *) (exten->command));
      case ERRORFLAG:  /* return code from the process */
        if (exten->type == EXECPROC)
          exec_command(exten);
        else
          shell_command(exten);
        long_ret = exten->result;
        return((u_char *) (&long_ret));
      case ERRORMSG:   /* first line of text returned from the process */
        if (exten->type == EXECPROC)
          exec_command(exten);
        else
          shell_command(exten);
        *var_len = strlen(exten->output);
        return((u_char *) (exten->output));
      case ERRORFIX:
        *write_method = fixExecError;
        long_return = 0;
        return ((u_char *) &long_return);

      case ERRORFIXCMD:
        *var_len = strlen(exten->fixcmd);
        return ((u_char *) exten->fixcmd);
    }
    return NULL;
  }
  return NULL;
}
unsigned char *
var_carpif_table(struct variable *vp, oid *name, size_t *length, int exact,
		size_t *var_len, WriteMethod **write_method)
{
	int index, cnt;
	struct carpif carp;
	static u_long ulong_ret;
	static char ifname[IFNAMSIZ];

	if ((cnt = carpif_count()) == -1)
		return (NULL);

	if (header_simple_table(vp, name, length, exact, var_len, write_method, cnt)
			== MATCH_FAILED)
		return (NULL);

	index = name[*length-1]-1;
	if (carpif_get(index, &carp))
		return (NULL);

	switch (vp->magic) {
		case CARPIF_INDEX:
			ulong_ret = name[*length-1];
			return (unsigned char *) &ulong_ret;
		case CARPIF_DESCR:
			*var_len = strlcpy(ifname, carp.ifname, 
						sizeof(ifname));
			return (unsigned char *) ifname;
		case CARPIF_VHID:
			ulong_ret = carp.carpr.carpr_vhids[0];
			return (unsigned char *) &ulong_ret;
		case CARPIF_DEV:
			*var_len = strlcpy(ifname, carp.carpr.carpr_carpdev,
					sizeof(ifname));
			return (unsigned char *) ifname;
		case CARPIF_ADVBASE:
			ulong_ret = carp.carpr.carpr_advbase;
			return (unsigned char *) &ulong_ret;
		case CARPIF_ADVSKEW:
			ulong_ret = carp.carpr.carpr_advskews[0];
			return (unsigned char *) &ulong_ret;
		case CARPIF_STATE:
			ulong_ret = carp.carpr.carpr_states[0];
			return (unsigned char *) &ulong_ret;
		default:
			return (NULL);
	}
	
	/* NOTREACHED */
}
/*
 * var_parameterTable():
 *   Handle this table separately from the scalar value case.
 *   The workings of this are basically the same as for var_parameter above.
 */
unsigned char *
var_parameterTable(struct variable *vp,
                   oid     *name,
                   size_t  *length,
                   int exact,
                   size_t  *var_len,
                   WriteMethod **write_method)
{
	//int index = 0;
	//static int idx = 0;
	static u_char VAR[MAX_CHAR_LEN]={0};
	MIBIDSTRUCT      *p_getNode = NULL;

	/*
	 * This assumes that the table is a 'simple' table.
	 *	See the implementation documentation for the meaning of this.
	 *	You will need to provide the correct value for the gi_parameterTableNum
	 *
	 * If this table does not meet the requirements for a simple table,
	 *	you will need to provide the replacement code yourself.
	 *	Mib2c is not smart enough to write this for you.
	 *    Again, see the implementation documentation for what is required.
	 */
	if (header_simple_table(vp,name,length,exact,var_len,write_method,gi_parameterTableNum)
	    == MATCH_FAILED)
		return NULL;

	if(FAILURE == check_row_index_parameterTable(name[*length - 1]))
		return NULL;

	DEBUGMSGTL(("parameter", "magic = %d\n",vp->magic));
	/* 我们替换掉switch结构
	   首先,根据magic查找请求的节点*/
	p_getNode =
	        get_table_node_parameterTable_withmagic(name[*length - 1], vp->magic );

	/* 如果没有找到直接返回 */
	if(p_getNode == NULL) return NULL;

	/* 如果对象可写,则赋值设置函数 */
	if(vp->acl == NETSNMP_OLDAPI_RWRITE)
		*write_method = write_parameterTable; // 每个表格统一使用一个写函数

	/*  最后返回获取的数据 */
	*var_len = snmp_get_data_parameter(p_getNode,VAR) ;
	DEBUGMSG(("parameter"," --No.=%d,len=%d\n ",p_getNode->t_tacheID.ipcNo,*var_len));
	 if( *var_len > 0 )
		return VAR;
	return NULL;
}
Beispiel #16
0
u_char         *
var_diskio(struct variable * vp,
           oid * name,
           size_t * length,
           int exact, size_t * var_len, WriteMethod ** write_method)
{
    static long     long_ret;
    unsigned int    indx;

    if (getstats() == 1) {
        return NULL;
    }


    if (header_simple_table
        (vp, name, length, exact, var_len, write_method, num_drives)) {
        return NULL;
    }

    indx = (unsigned int) (name[*length - 1] - 1);

    if (indx >= num_drives)
        return NULL;

    switch (vp->magic) {
	case DISKIO_INDEX:
	    long_ret = (long) drivestat[indx].bsd_unit_number;
	    return (u_char *) & long_ret;
	case DISKIO_DEVICE:
	    *var_len = strlen(drivestat[indx].name);
	    return (u_char *) drivestat[indx].name;
	case DISKIO_NREAD:
	    long_ret = (signed long) drivestat[indx].stats[kIDXBytesRead];
	    return (u_char *) & long_ret;
	case DISKIO_NWRITTEN:
	    long_ret = (signed long) drivestat[indx].stats[kIDXBytesWritten];
	    return (u_char *) & long_ret;
	case DISKIO_READS:
	    long_ret = (signed long) drivestat[indx].stats[kIDXNumReads];
	    return (u_char *) & long_ret;
	case DISKIO_WRITES:
	    long_ret = (signed long) drivestat[indx].stats[kIDXNumWrites];
	    return (u_char *) & long_ret;

	default:
	    ERROR_MSG("diskio.c: don't know how to handle this request.");
    }
    return NULL;
}
Beispiel #17
0
netsnmp_subtree *
find_extensible(netsnmp_subtree *tp, oid *tname, size_t tnamelen, int exact)
{
    size_t          tmp;
    int             i;
    struct extensible *exten = 0;
    struct variable myvp;
    oid             name[MAX_OID_LEN];
    static netsnmp_subtree mysubtree[2] =
	{ { NULL, 0, NULL, 0, NULL, 0, NULL, 0, 0, NULL, NULL, 0, 0, 0,
	    NULL, NULL, NULL, 0, 0, NULL, 0, 0 },
	  { NULL, 0, NULL, 0, NULL, 0, NULL, 0, 0, NULL, NULL, 0, 0, 0,
	    NULL, NULL, NULL, 0, 0, NULL, 0, 0 } };

    for (i = 1; i <= (int) numrelocs; i++) {
        exten = get_exten_instance(relocs, i);
        if (!exten)
            continue;
        if (exten->miblen != 0) {
            memcpy(myvp.name, exten->miboid, exten->miblen * sizeof(oid));
            memcpy(name, tname, tnamelen * sizeof(oid));
            myvp.name[exten->miblen] = name[exten->miblen];
            myvp.namelen = exten->miblen + 1;
            tmp = exten->miblen + 1;
            if (!header_simple_table(&myvp, name, &tmp, -1, 
				     NULL, NULL, numrelocs)) {
                break;
	    }
        }
    }
    if (i > (int)numrelocs || exten == NULL) {
        return (tp);
    }

    if (mysubtree[0].name_a != NULL) {
	free(mysubtree[0].name_a);
	mysubtree[0].name_a = NULL;
    }
    mysubtree[0].name_a  = snmp_duplicate_objid(exten->miboid, exten->miblen);
    mysubtree[0].namelen = exten->miblen;
    mysubtree[0].variables = (struct variable *)extensible_relocatable_variables;
    mysubtree[0].variables_len = sizeof(extensible_relocatable_variables) /
        sizeof(*extensible_relocatable_variables);
    mysubtree[0].variables_width = sizeof(*extensible_relocatable_variables);
    mysubtree[1].namelen = 0;
    return (mysubtree);
}
Beispiel #18
0
u_char         *
var_diskio(struct variable * vp,
           oid * name,
           size_t * length,
           int exact, size_t * var_len, WriteMethod ** write_method)
{
    static long     long_ret;
    unsigned int    indx;

    if (getstats() == 0)
        return 0;

    if (header_simple_table
        (vp, name, length, exact, var_len, write_method, ndisk))
        return NULL;

    indx = (unsigned int) (name[*length - 1] - 1);
    if (indx >= ndisk)
        return NULL;

    switch (vp->magic) {
    case DISKIO_INDEX:
        long_ret = (long) indx + 1;
        return (u_char *) & long_ret;
    case DISKIO_DEVICE:
        *var_len = strlen(dkname[indx]);
        return (u_char *) dkname[indx];
    case DISKIO_NREAD:
        long_ret =
            (signed long) (dk[indx].dk_sectors * dk[indx].dk_secsize);
        return (u_char *) & long_ret;
    case DISKIO_NWRITTEN:
        return NULL;            /* Sigh... BSD doesn't keep seperate track */
    case DISKIO_READS:
        long_ret = (signed long) dk[indx].dk_xfers;
        return (u_char *) & long_ret;
    case DISKIO_WRITES:
        return NULL;            /* Sigh... BSD doesn't keep seperate track */

    default:
        ERROR_MSG("diskio.c: don't know how to handle this request.");
    }
    return NULL;
}
Beispiel #19
0
/*
 * var_dot3PauseTable():
 *   Handle this table separately from the scalar value case.
 *   The workings of this are basically the same as for var_dot3PauseTable above.
 */
unsigned char *
var_dot3PauseTable(struct variable *vp,
            oid     *name,
            size_t  *length,
            int     exact,
            size_t  *var_len,
            WriteMethod **write_method)
{
    /* variables we may use later */
    static long long_ret;
    static unsigned char string[SPRINT_MAX_LEN];
    static oid objid[MAX_OID_LEN];
    static struct counter64 c64;

    if (header_simple_table(vp,name,length,exact,var_len,write_method, TABLE_SIZE)
        == MATCH_FAILED )
        return NULL;
    
    switch(vp->magic) {
    case DOT3PAUSEADMINMODE:
        *write_method = write_dot3PauseAdminMode;
        long_ret = 0;
        return (unsigned char *) &long_ret;

    case DOT3PAUSEOPERMODE:
        long_ret = 0;
        return (unsigned char *) &long_ret;

    case DOT3INPAUSEFRAMES:
        long_ret = 0;
        return (unsigned char *) &long_ret;

    case DOT3OUTPAUSEFRAMES:
        long_ret = 0;
        return (unsigned char *) &long_ret;

    default:
        ERROR_MSG("");
    }
    return NULL;
}
Beispiel #20
0
static u_char *ast_var_indications_table(struct variable *vp, oid *name, size_t *length,
        int exact, size_t *var_len, WriteMethod **write_method)
{
    static unsigned long long_ret;
    struct tone_zone *tz = NULL;
    int i;

    if (header_simple_table(vp, name, length, exact, var_len, write_method, -1))
        return NULL;

    i = name[*length - 1] - 1;
    while ( (tz = ast_walk_indications(tz)) && i )
        i--;
    if (tz == NULL)
        return NULL;

    switch (vp->magic) {
    case ASTINDINDEX:
        long_ret = name[*length - 1];
        return (u_char *)&long_ret;
    case ASTINDCOUNTRY:
        *var_len = strlen(tz->country);
        return (u_char *)tz->country;
    case ASTINDALIAS:
        if (tz->alias) {
            *var_len = strlen(tz->alias);
            return (u_char *)tz->alias;
        }
        return NULL;
    case ASTINDDESCRIPTION:
        *var_len = strlen(tz->description);
        return (u_char *)tz->description;
    default:
        break;
    }
    return NULL;
}
Beispiel #21
0
void*
snmp_header_list_table(struct variable *vp, oid *name, size_t *length,
		  int exact, size_t *var_len, WriteMethod **write_method, list dlist)
{
	element e;
	void *scr;
	unsigned int target, current;

	if (header_simple_table(vp, name, length, exact, var_len, write_method, -1))
		return NULL;

	if (LIST_ISEMPTY(dlist))
		return NULL;

	target = name[*length - 1];
	current = 0;

	for (e = LIST_HEAD(dlist); e; ELEMENT_NEXT(e)) {
		scr = ELEMENT_DATA(e);
		current++;
		if (current == target)
			/* Exact match */
			return scr;
		if (current < target)
			/* No match found yet */
			continue;
		if (exact)
			/* No exact match found */
			return NULL;
		/* current is the best match */
		name[*length - 1] = current;
		return scr;
	}
	/* No macth found at end */
	return NULL;
}
Beispiel #22
0
u_char         *
var_diskio(struct variable * vp,
           oid * name,
           size_t * length,
           int exact, size_t * var_len, WriteMethod ** write_method)
{
    /*
     * define any variables we might return as static! 
     */
    static long     long_ret;
    static struct counter64 c64_ret;

    if (header_simple_table
        (vp, name, length, exact, var_len, write_method, MAX_DISKS))
        return NULL;


    if (get_disk(name[*length - 1] - 1) == 0)
        return NULL;


    /*
     * We can now simply test on vp's magic number, defined in diskio.h 
     */
    switch (vp->magic) {
    case DISKIO_INDEX:
        long_ret = (long) name[*length - 1];
        return (u_char *) & long_ret;
    case DISKIO_DEVICE:
        *var_len = strlen(ksp->ks_name);
        return (u_char *) ksp->ks_name;
    case DISKIO_NREAD:
        long_ret = (uint32_t) kio.nread;
        return (u_char *) & long_ret;
    case DISKIO_NWRITTEN:
        long_ret = (uint32_t) kio.nwritten;
        return (u_char *) & long_ret;
    case DISKIO_NREADX:
        *var_len = sizeof(struct counter64);
        c64_ret.low = kio.nread & 0xffffffff;;
        c64_ret.high = kio.nread >> 32;
        return (u_char *) & c64_ret;
    case DISKIO_NWRITTENX:
        *var_len = sizeof(struct counter64);
        c64_ret.low = kio.nwritten & 0xffffffff;;
        c64_ret.high = kio.nwritten >> 32;
        return (u_char *) & c64_ret;
    case DISKIO_READS:
        long_ret = (uint32_t) kio.reads;
        return (u_char *) & long_ret;
    case DISKIO_WRITES:
        long_ret = (uint32_t) kio.writes;
        return (u_char *) & long_ret;

    default:
        ERROR_MSG("diskio.c: don't know how to handle this request.");
    }
    /*
     * if we fall to here, fail by returning NULL 
     */
    return NULL;
}
Beispiel #23
0
u_char         *
var_extensible_regexp_proc(struct variable *vp,
                    oid * name,
                    size_t * length,
                    int exact,
                    size_t * var_len, WriteMethod ** write_method)
{

    struct myregexp_proc  *proc;
    static long     long_ret;
    static char     errmsg[300];


    if (header_simple_table
        (vp, name, length, exact, var_len, write_method, numprocs))
        return (NULL);

    if ((proc = get_regexp_proc_instance(regexp_procwatch, name[*length - 1]))) {
        switch (vp->magic) {
        case MIBINDEX:
            long_ret = name[*length - 1];
            return ((u_char *) (&long_ret));
        case ERRORNAME:        /* process name to check for */
            *var_len = strlen(proc->name);
            return ((u_char *) (proc->name));
        case PROCMIN:
            long_ret = proc->min;
            return ((u_char *) (&long_ret));
        case PROCMAX:
            long_ret = proc->max;
            return ((u_char *) (&long_ret));
        case PROCCOUNT:
            long_ret = sh_count_regexp_procs(proc->name, proc->regexp);
            return ((u_char *) (&long_ret));
        case ERRORFLAG:
            long_ret = sh_count_regexp_procs(proc->name, proc->regexp);
            if (long_ret >= 0 &&
                   /* Too few processes running */
                ((proc->min && long_ret < proc->min) ||
                   /* Too many processes running */
                 (proc->max && long_ret > proc->max) ||
                   /* Processes running that shouldn't be */
                 (proc->min == 0 && proc->max == 0 && long_ret > 0))) {
                long_ret = 1;
            } else {
                long_ret = 0;
            }
            return ((u_char *) (&long_ret));
        case ERRORMSG:
            long_ret = sh_count_regexp_procs(proc->name, proc->regexp);
            if (long_ret < 0) {
                errmsg[0] = 0;  /* catch out of mem errors return 0 count */
            } else if (proc->min && long_ret < proc->min) {
                if ( long_ret > 0 )
                    snprintf(errmsg, sizeof(errmsg),
                        "Too few %s running (# = %d)",
                        proc->name, (int) long_ret);
                else
                    snprintf(errmsg, sizeof(errmsg),
                        "No %s process running", proc->name);
            } else if (proc->max && long_ret > proc->max) {
                snprintf(errmsg, sizeof(errmsg),
                        "Too many %s running (# = %d)",
                        proc->name, (int) long_ret);
            } else if (proc->min == 0 && proc->max == 0 && long_ret > 0) {
                snprintf(errmsg, sizeof(errmsg),
                        "%s process should not be running.", proc->name);
            } else {
                errmsg[0] = 0;
            }
            errmsg[ sizeof(errmsg)-1 ] = 0;
            *var_len = strlen(errmsg);
            return ((u_char *) errmsg);
        case ERRORFIX:
            *write_method = fixRegexpProcError;
            long_return = fixproc.result;
            return ((u_char *) & long_return);
        case ERRORFIXCMD:
            if (proc->fixcmd) {
                *var_len = strlen(proc->fixcmd);
                return (u_char *) proc->fixcmd;
            }
            errmsg[0] = 0;
            *var_len = 0;
            return ((u_char *) errmsg);
        }
        return NULL;
    }
    return NULL;
}
Beispiel #24
0
static u_char *ast_var_channels_table(struct variable *vp, oid *name, size_t *length,
									int exact, size_t *var_len, WriteMethod **write_method)
{
	static unsigned long long_ret;
	static u_char bits_ret[2];
	static char string_ret[256];
	struct ast_channel *chan, *bridge;
	struct timeval tval;
	u_char *ret = NULL;
	int i, bit;
	struct ast_str *out = ast_str_alloca(2048);
	struct ast_channel_iterator *iter;

	if (header_simple_table(vp, name, length, exact, var_len, write_method, ast_active_channels()))
		return NULL;

	i = name[*length - 1] - 1;

	if (!(iter = ast_channel_iterator_all_new())) {
		return NULL;
	}

	while ((chan = ast_channel_iterator_next(iter)) && i) {
		ast_channel_unref(chan);
		i--;
	}

	iter = ast_channel_iterator_destroy(iter);

	if (chan == NULL) {
		return NULL;
	}

	*var_len = sizeof(long_ret);

	ast_channel_lock(chan);

	switch (vp->magic) {
	case ASTCHANINDEX:
		long_ret = name[*length - 1];
		ret = (u_char *)&long_ret;
		break;
	case ASTCHANNAME:
		if (!ast_strlen_zero(ast_channel_name(chan))) {
			ast_copy_string(string_ret, ast_channel_name(chan), sizeof(string_ret));
			*var_len = strlen(string_ret);
			ret = (u_char *)string_ret;
		}
		break;
	case ASTCHANLANGUAGE:
		if (!ast_strlen_zero(ast_channel_language(chan))) {
			ast_copy_string(string_ret, ast_channel_language(chan), sizeof(string_ret));
			*var_len = strlen(string_ret);
			ret = (u_char *)string_ret;
		}
		break;
	case ASTCHANTYPE:
		ast_copy_string(string_ret, ast_channel_tech(chan)->type, sizeof(string_ret));
		*var_len = strlen(string_ret);
		ret = (u_char *)string_ret;
		break;
	case ASTCHANMUSICCLASS:
		if (!ast_strlen_zero(ast_channel_musicclass(chan))) {
			ast_copy_string(string_ret, ast_channel_musicclass(chan), sizeof(string_ret));
			*var_len = strlen(string_ret);
			ret = (u_char *)string_ret;
		}
		break;
	case ASTCHANBRIDGE:
		if ((bridge = ast_bridged_channel(chan)) != NULL) {
			ast_copy_string(string_ret, ast_channel_name(bridge), sizeof(string_ret));
			*var_len = strlen(string_ret);
			ret = (u_char *)string_ret;
		}
		break;
	case ASTCHANMASQ:
		if (ast_channel_masq(chan) && !ast_strlen_zero(ast_channel_name(ast_channel_masq(chan)))) {
			ast_copy_string(string_ret, ast_channel_name(ast_channel_masq(chan)), sizeof(string_ret));
			*var_len = strlen(string_ret);
			ret = (u_char *)string_ret;
		}
		break;
	case ASTCHANMASQR:
		if (ast_channel_masqr(chan) && !ast_strlen_zero(ast_channel_name(ast_channel_masqr(chan)))) {
			ast_copy_string(string_ret, ast_channel_name(ast_channel_masqr(chan)), sizeof(string_ret));
			*var_len = strlen(string_ret);
			ret = (u_char *)string_ret;
		}
		break;
	case ASTCHANWHENHANGUP:
		if (!ast_tvzero(*ast_channel_whentohangup(chan))) {
			gettimeofday(&tval, NULL);
			long_ret = difftime(ast_channel_whentohangup(chan)->tv_sec, tval.tv_sec) * 100 - tval.tv_usec / 10000;
			ret= (u_char *)&long_ret;
		}
		break;
	case ASTCHANAPP:
		if (ast_channel_appl(chan)) {
			ast_copy_string(string_ret, ast_channel_appl(chan), sizeof(string_ret));
			*var_len = strlen(string_ret);
			ret = (u_char *)string_ret;
		}
		break;
	case ASTCHANDATA:
		if (ast_channel_data(chan)) {
			ast_copy_string(string_ret, ast_channel_data(chan), sizeof(string_ret));
			*var_len = strlen(string_ret);
			ret = (u_char *)string_ret;
		}
		break;
	case ASTCHANCONTEXT:
		ast_copy_string(string_ret, ast_channel_context(chan), sizeof(string_ret));
		*var_len = strlen(string_ret);
		ret = (u_char *)string_ret;
		break;
	case ASTCHANMACROCONTEXT:
		ast_copy_string(string_ret, ast_channel_macrocontext(chan), sizeof(string_ret));
		*var_len = strlen(string_ret);
		ret = (u_char *)string_ret;
		break;
	case ASTCHANMACROEXTEN:
		ast_copy_string(string_ret, ast_channel_macroexten(chan), sizeof(string_ret));
		*var_len = strlen(string_ret);
		ret = (u_char *)string_ret;
		break;
	case ASTCHANMACROPRI:
		long_ret = ast_channel_macropriority(chan);
		ret = (u_char *)&long_ret;
		break;
	case ASTCHANEXTEN:
		ast_copy_string(string_ret, ast_channel_exten(chan), sizeof(string_ret));
		*var_len = strlen(string_ret);
		ret = (u_char *)string_ret;
		break;
	case ASTCHANPRI:
		long_ret = ast_channel_priority(chan);
		ret = (u_char *)&long_ret;
		break;
	case ASTCHANACCOUNTCODE:
		if (!ast_strlen_zero(ast_channel_accountcode(chan))) {
			ast_copy_string(string_ret, ast_channel_accountcode(chan), sizeof(string_ret));
			*var_len = strlen(string_ret);
			ret = (u_char *)string_ret;
		}
		break;
	case ASTCHANFORWARDTO:
		if (!ast_strlen_zero(ast_channel_call_forward(chan))) {
			ast_copy_string(string_ret, ast_channel_call_forward(chan), sizeof(string_ret));
			*var_len = strlen(string_ret);
			ret = (u_char *)string_ret;
		}
		break;
	case ASTCHANUNIQUEID:
		ast_copy_string(string_ret, ast_channel_uniqueid(chan), sizeof(string_ret));
		*var_len = strlen(string_ret);
		ret = (u_char *)string_ret;
		break;
	case ASTCHANCALLGROUP:
		long_ret = ast_channel_callgroup(chan);
		ret = (u_char *)&long_ret;
		break;
	case ASTCHANPICKUPGROUP:
		long_ret = ast_channel_pickupgroup(chan);
		ret = (u_char *)&long_ret;
		break;
	case ASTCHANSTATE:
		long_ret = ast_channel_state(chan) & 0xffff;
		ret = (u_char *)&long_ret;
		break;
	case ASTCHANMUTED:
		long_ret = ast_channel_state(chan) & AST_STATE_MUTE ? 1 : 2;
		ret = (u_char *)&long_ret;
		break;
	case ASTCHANRINGS:
		long_ret = ast_channel_rings(chan);
		ret = (u_char *)&long_ret;
		break;
	case ASTCHANCIDDNID:
		if (ast_channel_dialed(chan)->number.str) {
			ast_copy_string(string_ret, ast_channel_dialed(chan)->number.str, sizeof(string_ret));
			*var_len = strlen(string_ret);
			ret = (u_char *)string_ret;
		}
		break;
	case ASTCHANCIDNUM:
		if (ast_channel_caller(chan)->id.number.valid && ast_channel_caller(chan)->id.number.str) {
			ast_copy_string(string_ret, ast_channel_caller(chan)->id.number.str, sizeof(string_ret));
			*var_len = strlen(string_ret);
			ret = (u_char *)string_ret;
		}
		break;
	case ASTCHANCIDNAME:
		if (ast_channel_caller(chan)->id.name.valid && ast_channel_caller(chan)->id.name.str) {
			ast_copy_string(string_ret, ast_channel_caller(chan)->id.name.str, sizeof(string_ret));
			*var_len = strlen(string_ret);
			ret = (u_char *)string_ret;
		}
		break;
	case ASTCHANCIDANI:
		if (ast_channel_caller(chan)->ani.number.valid && ast_channel_caller(chan)->ani.number.str) {
			ast_copy_string(string_ret, ast_channel_caller(chan)->ani.number.str, sizeof(string_ret));
			*var_len = strlen(string_ret);
			ret = (u_char *)string_ret;
		}
		break;
	case ASTCHANCIDRDNIS:
		if (ast_channel_redirecting(chan)->from.number.valid && ast_channel_redirecting(chan)->from.number.str) {
			ast_copy_string(string_ret, ast_channel_redirecting(chan)->from.number.str, sizeof(string_ret));
			*var_len = strlen(string_ret);
			ret = (u_char *)string_ret;
		}
		break;
	case ASTCHANCIDPRES:
		long_ret = ast_party_id_presentation(&ast_channel_caller(chan)->id);
		ret = (u_char *)&long_ret;
		break;
	case ASTCHANCIDANI2:
		long_ret = ast_channel_caller(chan)->ani2;
		ret = (u_char *)&long_ret;
		break;
	case ASTCHANCIDTON:
		long_ret = ast_channel_caller(chan)->id.number.plan;
		ret = (u_char *)&long_ret;
		break;
	case ASTCHANCIDTNS:
		long_ret = ast_channel_dialed(chan)->transit_network_select;
		ret = (u_char *)&long_ret;
		break;
	case ASTCHANAMAFLAGS:
		long_ret = ast_channel_amaflags(chan);
		ret = (u_char *)&long_ret;
		break;
	case ASTCHANADSI:
		long_ret = ast_channel_adsicpe(chan);
		ret = (u_char *)&long_ret;
		break;
	case ASTCHANTONEZONE:
		if (ast_channel_zone(chan)) {
			ast_copy_string(string_ret, ast_channel_zone(chan)->country, sizeof(string_ret));
			*var_len = strlen(string_ret);
			ret = (u_char *)string_ret;
		}
		break;
	case ASTCHANHANGUPCAUSE:
		long_ret = ast_channel_hangupcause(chan);
		ret = (u_char *)&long_ret;
		break;
	case ASTCHANVARIABLES:
		if (pbx_builtin_serialize_variables(chan, &out)) {
			*var_len = ast_str_strlen(out);
			ret = (u_char *)ast_str_buffer(out);
		}
		break;
	case ASTCHANFLAGS:
		bits_ret[0] = 0;
		for (bit = 0; bit < 8; bit++)
			bits_ret[0] |= ((ast_channel_flags(chan)->flags & (1 << bit)) >> bit) << (7 - bit);
		bits_ret[1] = 0;
		for (bit = 0; bit < 8; bit++)
			bits_ret[1] |= (((ast_channel_flags(chan)->flags >> 8) & (1 << bit)) >> bit) << (7 - bit);
		*var_len = 2;
		ret = bits_ret;
		break;
	case ASTCHANTRANSFERCAP:
		long_ret = ast_channel_transfercapability(chan);
		ret = (u_char *)&long_ret;
	default:
		break;
	}

	ast_channel_unlock(chan);
	chan = ast_channel_unref(chan);

	return ret;
}
Beispiel #25
0
static u_char *
var_logmatch_table(struct variable *vp,
                   oid * name,
                   size_t * length,
                   int exact,
                   size_t * var_len, WriteMethod ** write_method)
{
    static long     long_ret;
    static char     message[1024];
    int             iindex;
    struct logmatchstat *logmatch;

    if (vp->magic == LOGMATCH_INFO) {
        if (header_generic(vp, name, length, exact, var_len, write_method)
            == MATCH_FAILED)
            return (NULL);
    } else {
        if (header_simple_table
            (vp, name, length, exact, var_len, write_method,
             logmatchCount))
            return (NULL);
    }


    iindex = name[*length - 1] - 1;
    logmatch = &logmatchTable[iindex];

    if (logmatch->myRegexError == 0)
        updateLogmatch(iindex);

    switch (vp->magic) {
    case LOGMATCH_INFO:
        long_ret = MAXLOGMATCH;
        return (u_char *) & long_ret;

    case LOGMATCH_INDEX:
        long_ret = iindex + 1;
        return (u_char *) & long_ret;

    case LOGMATCH_NAME:
        *var_len = strlen(logmatch->name);
        return (u_char *) logmatch->name;

    case LOGMATCH_FILENAME:
        *var_len = strlen(logmatch->filename);
        return (u_char *) logmatch->filename;

    case LOGMATCH_REGEX:
        *var_len = strlen(logmatch->regEx);
        return (u_char *) logmatch->regEx;

    case LOGMATCH_GLOBALCTR:
    case LOGMATCH_GLOBALCNT:
        long_ret = (logmatch->globalMatchCounter);
        return (u_char *) & long_ret;

    case LOGMATCH_CURRENTCTR:
    case LOGMATCH_CURRENTCNT:
        long_ret = (logmatch->currentMatchCounter);
        return (u_char *) & long_ret;

    case LOGMATCH_COUNTER:
    case LOGMATCH_COUNT:
        long_ret = (logmatch->matchCounter);
        logmatch->matchCounter = 0;
        return (u_char *) & long_ret;

    case LOGMATCH_FREQ:
        long_ret = logmatch->frequency;
        return (u_char *) & long_ret;

    case LOGMATCH_ERROR:
        if (logmatch->frequency >= 0 && logmatch->myRegexError == 0)
            long_ret = 0;
        else
            long_ret = 1;

        return (u_char *) & long_ret;

    case LOGMATCH_MSG:

        regerror(logmatch->myRegexError, &(logmatch->regexBuffer), message,
                 sizeof(message));

        *var_len = strlen(message);
        return (u_char *) message;

    default:
        DEBUGMSGTL(("snmpd", "unknown sub-id %d in var_logmatch_table\n",
                    vp->magic));
    }

    return NULL;
}
Beispiel #26
0
/*
 * var_lmSensorsTable():
 *   Handle this table separately from the scalar value case.
 *   The workings of this are basically the same as for var_lmSensors above.
 */
unsigned char  *
var_lmSensorsTable(struct variable *vp,
                   oid * name,
                   size_t * length,
                   int exact,
                   size_t * var_len, WriteMethod ** write_method)
{
    static long     long_ret;
    static char     string[SPRINT_MAX_LEN];

    int             s_index;
    int             s_type = -1;
    int             n_sensors;
    unsigned char* ret = NULL;

    _sensor         s;

    if (sensor_load())
    {
        ret = NULL;
        goto leaving;
    }

    switch (vp->magic) {
    case LMTEMPSENSORSINDEX:
    case LMTEMPSENSORSDEVICE:
    case LMTEMPSENSORSVALUE:
        s_type = TEMP_TYPE;
        n_sensors = sensor_array[s_type].n;
        break;

    case LMFANSENSORSINDEX:
    case LMFANSENSORSDEVICE:
    case LMFANSENSORSVALUE:
        s_type = FAN_TYPE;
        n_sensors = sensor_array[s_type].n;
        break;

    case LMVOLTSENSORSINDEX:
    case LMVOLTSENSORSDEVICE:
    case LMVOLTSENSORSVALUE:
        s_type = VOLT_TYPE;
        n_sensors = sensor_array[s_type].n;
        break;

    case LMMISCSENSORSINDEX:
    case LMMISCSENSORSDEVICE:
    case LMMISCSENSORSVALUE:
        s_type = MISC_TYPE;
        n_sensors = sensor_array[s_type].n;
        break;

    default:
        s_type = -1;
        n_sensors = 0;
    }

    if (header_simple_table(vp, name, length, exact,
                            var_len, write_method,
                            n_sensors) == MATCH_FAILED)
    {
        ret = NULL;
        goto leaving;
    }

    if (s_type < 0)
    {
        ret = NULL;
        goto leaving;
    }

    s_index = name[*length - 1] - 1;
    s = sensor_array[s_type].sensor[s_index];

    switch (vp->magic) {
    case LMTEMPSENSORSINDEX:
    case LMFANSENSORSINDEX:
    case LMVOLTSENSORSINDEX:
    case LMMISCSENSORSINDEX:
        long_ret = s_index;
        ret = (unsigned char *) &long_ret;
        goto leaving;

    case LMTEMPSENSORSDEVICE:
    case LMFANSENSORSDEVICE:
    case LMVOLTSENSORSDEVICE:
    case LMMISCSENSORSDEVICE:
        strlcpy(string, s.name, sizeof(string));
        *var_len = strlen(string);
        ret = (unsigned char *) string;
        goto leaving;

    case LMTEMPSENSORSVALUE:
    case LMFANSENSORSVALUE:
    case LMVOLTSENSORSVALUE:
    case LMMISCSENSORSVALUE:
        long_ret = s.value;
        ret = (unsigned char *) &long_ret;
        goto leaving;

    default:
        ERROR_MSG("Unable to handle table request");
    }

leaving:
    return ret;
}
Beispiel #27
0
u_char         *
var_diskio(struct variable * vp,
           oid * name,
           size_t * length,
           int exact, size_t * var_len, WriteMethod ** write_method)
{
    static long     long_ret;
    static struct   counter64 c64_ret;
    long long       longlong_ret;
    unsigned int    indx;

    if (getstats() == 1) {
        return NULL;
    }


    if (header_simple_table
        (vp, name, length, exact, var_len, write_method, ndisk)) {
        return NULL;
    }

    indx = (unsigned int) (name[*length - 1] - 1);

    if (indx >= ndisk)
        return NULL;

    switch (vp->magic) {
    case DISKIO_INDEX:
        long_ret = (long) indx + 1;;
        return (u_char *) & long_ret;
    case DISKIO_DEVICE:
        *var_len = strlen(stat->dinfo->devices[indx].device_name);
        return (u_char *) stat->dinfo->devices[indx].device_name;
    case DISKIO_NREAD:
#if defined(freebsd5) && __FreeBSD_version >= 500107
        long_ret = (signed long) stat->dinfo->devices[indx].bytes[DEVSTAT_READ];
#else
        long_ret = (signed long) stat->dinfo->devices[indx].bytes_read;
#endif
        return (u_char *) & long_ret;
    case DISKIO_NWRITTEN:
#if defined(freebsd5) && __FreeBSD_version >= 500107
        long_ret = (signed long) stat->dinfo->devices[indx].bytes[DEVSTAT_WRITE];
#else
        long_ret = (signed long) stat->dinfo->devices[indx].bytes_written;
#endif
        return (u_char *) & long_ret;
    case DISKIO_NREADX:
        *var_len = sizeof(struct counter64);
#if defined(freebsd5) && __FreeBSD_version >= 500107
        longlong_ret = stat->dinfo->devices[indx].bytes[DEVSTAT_READ];
#else
        longlong_ret = stat->dinfo->devices[indx].bytes_read;
#endif
        c64_ret.low = longlong_ret & 0xffffffff;
        c64_ret.high = longlong_ret >> 32;
        return (u_char *) & c64_ret;
    case DISKIO_NWRITTENX:
        *var_len = sizeof(struct counter64);
#if defined(freebsd5) && __FreeBSD_version >= 500107
        longlong_ret = stat->dinfo->devices[indx].bytes[DEVSTAT_WRITE];
#else
        longlong_ret = stat->dinfo->devices[indx].bytes_written;
#endif
        c64_ret.low = longlong_ret & 0xffffffff;
        c64_ret.high = longlong_ret >> 32;
        return (u_char *) & c64_ret;
    case DISKIO_READS:
#if defined(freebsd5) && __FreeBSD_version >= 500107
        long_ret = (signed long) stat->dinfo->devices[indx].operations[DEVSTAT_READ];
#else
        long_ret = (signed long) stat->dinfo->devices[indx].num_reads;
#endif
        return (u_char *) & long_ret;
    case DISKIO_WRITES:
#if defined(freebsd5) && __FreeBSD_version >= 500107
        long_ret = (signed long) stat->dinfo->devices[indx].operations[DEVSTAT_WRITE];
#else
        long_ret = (signed long) stat->dinfo->devices[indx].num_writes;
#endif
        return (u_char *) & long_ret;
    case DISKIO_LA1:
	long_ret = devloads[indx].la1;
	return (u_char *) & long_ret;
    case DISKIO_LA5:
        long_ret = devloads[indx].la5;
        return (u_char *) & long_ret;
    case DISKIO_LA15:
        long_ret = devloads[indx].la15;
        return (u_char *) & long_ret;

    default:
        ERROR_MSG("diskio.c: don't know how to handle this request.");
    }
    return NULL;
}
Beispiel #28
0
u_char         *
var_extensible_relocatable(struct variable *vp,
                           oid * name,
                           size_t * length,
                           int exact,
                           size_t * var_len, WriteMethod ** write_method)
{

    int             i;
    int             len;
    struct extensible *exten = 0;
    static long     long_ret;
    static char     errmsg[STRMAX];
    char            *cp, *cp1;
    struct variable myvp;
    oid             tname[MAX_OID_LEN];

    memcpy(&myvp, vp, sizeof(struct variable));

    long_ret = *length;
    for (i = 1; i <= (int) numrelocs; i++) {
        exten = get_exten_instance(relocs, i);
        if (!exten)
            continue;
        if ((int) exten->miblen == (int) vp->namelen - 1) {
            memcpy(myvp.name, exten->miboid, exten->miblen * sizeof(oid));
            myvp.namelen = exten->miblen;
            *length = vp->namelen;
            memcpy(tname, vp->name, vp->namelen * sizeof(oid));
            if (!header_simple_table
                (&myvp, tname, length, -1, var_len, write_method, -1))
                break;
            else
                exten = NULL;
        }
    }
    if (i > (int) numrelocs || exten == NULL) {
        *length = long_ret;
        *var_len = 0;
        *write_method = NULL;
        return (NULL);
    }

    *length = long_ret;
    if (header_simple_table(vp, name, length, exact, var_len, write_method,
                            ((vp->magic == ERRORMSG) ? MAXMSGLINES : 1)))
        return (NULL);

    switch (vp->magic) {
    case MIBINDEX:
        long_ret = name[*length - 1];
        return ((u_char *) (&long_ret));
    case ERRORNAME:            /* name defined in config file */
        *var_len = strlen(exten->name);
        return ((u_char *) (exten->name));
    case SHELLCOMMAND:
        *var_len = strlen(exten->command);
        return ((u_char *) (exten->command));
    case ERRORFLAG:            /* return code from the process */
        len = sizeof(exten->output);
        if (exten->type == EXECPROC)
            exten->result = run_exec_command( exten->command, NULL,
                                              exten->output, &len);
	else
            exten->result = run_shell_command(exten->command, NULL,
                                              exten->output, &len);
        long_ret = exten->result;
        return ((u_char *) (&long_ret));
    case ERRORMSG:             /* first line of text returned from the process */
        len = sizeof(exten->output);
        if (exten->type == EXECPROC)
            exten->result = run_exec_command( exten->command, NULL,
                                              exten->output, &len);
	else
            exten->result = run_shell_command(exten->command, NULL,
                                              exten->output, &len);

        /*
         *  Pick the output string apart into individual lines,
         *  and extract the one being asked for....
         */
        cp1 = exten->output;
        for (i = 1; i != (int) name[*length - 1]; i++) {
            cp = strchr(cp1, '\n');
            if (!cp) {
	        *var_len = 0;
	        /* wait_on_exec(exten);		??? */
	        return NULL;
	    }
	    cp1 = ++cp;
	}
        /*
         *  ... and quit if we've run off the end of the output
         */
        if (!*cp1) {
            *var_len = 0;
	    return NULL;
	}
        cp = strchr(cp1, '\n');
        if (cp)
            *cp = 0;
        strlcpy(errmsg, cp1, sizeof(errmsg));
        *var_len = strlen(errmsg);
        if (errmsg[*var_len - 1] == '\n')
            errmsg[--(*var_len)] = '\0';
        return ((u_char *) (errmsg));
    case ERRORFIX:
        *write_method = fixExecError;
        long_return = 0;
        return ((u_char *) & long_return);

    case ERRORFIXCMD:
        *var_len = strlen(exten->fixcmd);
        return ((u_char *) exten->fixcmd);
    }
    return NULL;
}
Beispiel #29
0
u_char *
var_diskio(struct variable * vp,
           oid * name,
           size_t * length,
           int exact, size_t * var_len, WriteMethod ** write_method)
{
    static long     long_ret;
    unsigned int    indx;

    if (getstats() == 0)
        return 0;

    if (header_simple_table
        (vp, name, length, exact, var_len, write_method, ndisk))
        return NULL;

    indx = (unsigned int) (name[*length - 1] - 1);
    if (indx >= ndisk)
        return NULL;

    switch (vp->magic) {
    case DISKIO_INDEX:
        long_ret = (long) indx + 1;
        return (u_char *) & long_ret;

    case DISKIO_DEVICE:
        *var_len = strlen(dkname[indx]);
        return (u_char *) dkname[indx];

    case DISKIO_NREAD:
#ifdef HW_DISKSTATS
     	long_ret = dk[indx].dk_rbytes;
#endif
#ifdef HW_IOSTATS
	if (dk[indx].type == IOSTAT_DISK)
	    long_ret = dk[indx].rbytes;
#endif
        return (u_char *) & long_ret;

    case DISKIO_NWRITTEN:
#ifdef HW_DISKSTATS
     	long_ret = dk[indx].dk_wbytes;
#endif
#ifdef HW_IOSTATS
	if (dk[indx].type == IOSTAT_DISK)
	    long_ret = dk[indx].wbytes;
#endif
        return (u_char *) & long_ret;

    case DISKIO_READS:
#ifdef HW_DISKSTATS
     	long_ret = dk[indx].dk_rxfer;
#endif
#ifdef HW_IOSTATS
	if (dk[indx].type == IOSTAT_DISK)
	    long_ret = dk[indx].rxfer;
#endif
        return (u_char *) & long_ret;

    case DISKIO_WRITES:
#ifdef HW_DISKSTATS
     	long_ret = dk[indx].dk_wxfer;
#endif
#ifdef HW_IOSTATS
	if (dk[indx].type == IOSTAT_DISK)
	    long_ret = dk[indx].wxfer;
#endif
        return (u_char *) & long_ret;

    default:
        ERROR_MSG("diskio.c: don't know how to handle this request.");
    }
    return NULL;
}
Beispiel #30
0
u_char * var_ipfwacc(struct variable *vp,
			    oid *name,
			    size_t *length,
			    int exact,
			    size_t *var_len,
			    WriteMethod **write_method)    
{
  *write_method = 0;           /* assume it isnt writable for the time being */
  *var_len = sizeof(ret_val);  /* assume an integer and change later if not */

  if (header_simple_table(vp,name,length,exact,var_len,write_method,readrule(0)))
	return (NULL);

  if (readrule(name[*length-1])){
    /* this is where we do the value assignments for the mib results. */
    switch(vp->magic) {
      case IPFWACCINDEX:
	ret_val = name[*length-1];
        return((u_char *) (&ret_val));
      case IPFWACCSRCADDR:
        atoip(0);
        return((u_char *) (&ret_val));
      case IPFWACCSRCNM:
        atoip(9);
        return((u_char *) (&ret_val));
      case IPFWACCDSTADDR:
        atoip(19);
        return((u_char *) (&ret_val));
      case IPFWACCDSTNM:
        atoip(28);
        return((u_char *) (&ret_val));
      case IPFWACCVIANAME:
	{ int i=37; /* position in the rule */
	  while (rule[i]!=' '&&i<IPFWRULELEN-1)
	    i++;
	  rule[i]=0;
	  return (rule+37);
	}
      case IPFWACCVIAADDR:
	{ int i=37; /* position in the rule */
	  while (rule[i]!=' '&&i<IPFWRULELEN-9)
	    i++;
	  atoip(i+1);
	  return((u_char *) (&ret_val));
	}
      case IPFWACCPROTO:
	switch (getflags()&IP_FW_F_KIND){
	case IP_FW_F_ALL: ret_val=2; return ((u_char *) (&ret_val));
	case IP_FW_F_TCP: ret_val=3; return ((u_char *) (&ret_val));
	case IP_FW_F_UDP: ret_val=4; return ((u_char *) (&ret_val));
	case IP_FW_F_ICMP: ret_val=5; return ((u_char *) (&ret_val));
	default: ret_val=1; return((u_char *) (&ret_val));
	}
      case IPFWACCBIDIR:
	ret_val=((getflags()&IP_FW_F_BIDIR)?2:1);
	return ((u_char *) (&ret_val));
      case IPFWACCDIR:
	ret_val=(getflags()&(IP_FW_F_ACCTIN|IP_FW_F_ACCTOUT));
        if (ret_val==IP_FW_F_ACCTIN)
	  ret_val=2;
	else if (ret_val==IP_FW_F_ACCTOUT)
	  ret_val=3;
	else
	  ret_val=1;
	return ((u_char *) (&ret_val));
      case IPFWACCBYTES:
	getnumeric(4);
	return ((u_char *) (&ret_val));
      case IPFWACCPACKETS:
	getnumeric(3);
        return ((u_char *) (&ret_val));
      case IPFWACCNSRCPRTS:
	getnumeric(1);
        return ((u_char *) (&ret_val));
      case IPFWACCNDSTPRTS:
	getnumeric(2);
        return ((u_char *) (&ret_val));
      case IPFWACCSRCISRNG:
	ret_val=((getflags()&IP_FW_F_SRNG)?1:2);
	return ((u_char *) (&ret_val));
      case IPFWACCDSTISRNG:
	ret_val=((getflags()&IP_FW_F_DRNG)?1:2);
	return ((u_char *) (&ret_val));
      case IPFWACCPORT1:
      case IPFWACCPORT2:
      case IPFWACCPORT3:
      case IPFWACCPORT4:
      case IPFWACCPORT5:
      case IPFWACCPORT6:
      case IPFWACCPORT7:
      case IPFWACCPORT8:
      case IPFWACCPORT9:
      case IPFWACCPORT10:
	getnumeric(5+(vp->magic)-IPFWACCPORT1);
        return ((u_char *) (&ret_val));
    }
  }
  return NULL;
}