Пример #1
0
u_char *
var_usmStats(
    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;
  int tmagic;

  *write_method = 0;           /* assume it isnt writable for the time being */
  *var_len = sizeof(long_ret); /* assume an integer and change later if not */

  if (header_generic(vp,name,length,exact,var_len,write_method))
      return 0;

  /* this is where we do the value assignments for the mib results. */
  tmagic = vp->magic;
  if ( (tmagic >= 0)
	&& (tmagic <= (STAT_USM_STATS_END - STAT_USM_STATS_START)) )
  {
    long_ret = snmp_get_statistic(tmagic + STAT_USM_STATS_START);
    return (unsigned char *) &long_ret;
  }
  return 0;
}
Пример #2
0
unsigned char *var_snmpGroup(struct variable *vp,
        					                  oid     *name,
        					                  size_t  *length,
        					                  int     exact,
        					                  size_t  *var_len,
        					                  WriteMethod **write_method)
{
	if(header_generic(vp, name, length, exact, var_len, write_method) ==  MATCH_FAILED)
	{
		return NULL;
	}
	else if( load_snmpGroup() != 0)
	{
		return NULL;
	}
	
	*var_len = sizeof (uint8_t); 
       *write_method = NULL;
	
	switch(vp->magic)
	{
		case OID_SNMP_VERSION:			
			*var_len = strlen(snmpGroup_snmpVersion);
			return snmpGroup_snmpVersion; 
			break;
		case OID_SNMP_READ_COMMUNITY:
			*write_method = write_readCommunity;
			*var_len = strlen(snmpGroup_readCommunity);
			return snmpGroup_readCommunity; 
			break;
		case OID_SNMP_WRITE_COMMUNITY:
			*write_method = write_writeCommunity;
			*var_len = strlen(snmpGroup_writeCommunity);
			return snmpGroup_writeCommunity; 
			break;
		case OID_SNMP_TRAP_VERSION:
			*var_len = strlen(snmpGroup_trapVersion);
			return snmpGroup_trapVersion; 
			break;
		case OID_SNMP_TRAP_COMMUNITY:
			*write_method = write_trapCommunity;
			*var_len = strlen(snmpGroup_trapCommunity);
			return snmpGroup_trapCommunity; 
			break;
		case OID_SNMP_TRAP_SERVER_IP_ADDRESS:
			*write_method = write_trapServerIpAddress;
			*var_len = strlen(snmpGroup_trapServerAddress);
			return snmpGroup_trapServerAddress; 
			break;
		case OID_SNMP_TRAP_SERVER_PORT:
			*write_method = write_trapServerport;
			*var_len = sizeof(snmpGroup_trapServerPort);
			return (unsigned char *) &snmpGroup_trapServerPort; 
			break;
		default:
			break;
	}
	return 0;
	
}
Пример #3
0
/*
 * var_parameter():
 *   This function is called every time the agent gets a request for
 *   a scalar variable that might be found within your mib section
 *   registered above.  It is up to you to do the right thing and
 *   return the correct value.
 *     You should also correct the value of "var_len" if necessary.
 *
 *   Please see the documentation for more information about writing
 *   module extensions, and check out the examples in the examples
 *   and mibII directories.
 */
unsigned char *
var_parameter(struct variable *vp,
              oid     *name,
              size_t  *length,
              int exact,
              size_t  *var_len,
              WriteMethod **write_method)
{
	static u_char VAR[MAX_CHAR_LEN]={0};
	MIBIDSTRUCT      *p_getNode = NULL;

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

	/* 我们替换掉switch结构
	   首先,根据magic查找请求的节点*/
	p_getNode = get_parameter_scalar_obj(vp->magic);

	/* 如果对象可写,则赋值设置函数 */
	if(vp->acl == NETSNMP_OLDAPI_RWRITE)
		*write_method = write_parameter_scalar;

	/*  最后返回获取的数据 */
	*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;
}
Пример #4
0
static u_char *ast_var_Config(struct variable *vp, oid *name, size_t *length,
                              int exact, size_t *var_len, WriteMethod **write_method)
{
    static unsigned long long_ret;
    struct timeval tval;

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

    switch (vp->magic) {
    case ASTCONFUPTIME:
        gettimeofday(&tval, NULL);
        long_ret = difftime(tval.tv_sec, ast_startuptime) * 100 + tval.tv_usec / 10000;
        return (u_char *)&long_ret;
    case ASTCONFRELOADTIME:
        gettimeofday(&tval, NULL);
        if (ast_lastreloadtime)
            long_ret = difftime(tval.tv_sec, ast_lastreloadtime) * 100 + tval.tv_usec / 10000;
        else
            long_ret = difftime(tval.tv_sec, ast_startuptime) * 100 + tval.tv_usec / 10000;
        return (u_char *)&long_ret;
    case ASTCONFPID:
        long_ret = getpid();
        return (u_char *)&long_ret;
    case ASTCONFSOCKET:
        *var_len = strlen(ast_config_AST_SOCKET);
        return (u_char *)ast_config_AST_SOCKET;
    default:
        break;
    }
    return NULL;
}
/*
 * var_notificationObjs():
 *   This function is called every time the agent gets a request for
 *   a scalar variable that might be found within your mib section
 *   registered above.  It is up to you to do the right thing and
 *   return the correct value.
 *     You should also correct the value of "var_len" if necessary.
 *
 *   Please see the documentation for more information about writing
 *   module extensions, and check out the examples in the examples
 *   and mibII directories.
 */
unsigned char  *
var_notificationObjs(struct variable *vp,
                     oid * name,
                     size_t *length,
                     int exact,
                     size_t *var_len, WriteMethod ** write_method)
{
	static long VAR;


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

    /*
     * this is where we do the value assignments for the mib results.
     */
    switch (vp->magic) {
    case ALARMCOUNTER:
        *write_method = write_alarmCounter;
 	    *var_len = sizeof(long); 		
        snmp_get_data(SHM_ALARM,ALARM_COUNTER,sizeof(long),&VAR); 
        return (u_char *) &VAR;
    default:
        ERROR_MSG("");
    }
    return NULL;
}
Пример #6
0
static u_char *ast_var_indications(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;

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

    switch (vp->magic) {
    case ASTINDCOUNT:
        long_ret = 0;
        while ( (tz = ast_walk_indications(tz)) )
            long_ret++;

        return (u_char *)&long_ret;
    case ASTINDCURRENT:
        tz = ast_get_indication_zone(NULL);
        if (tz) {
            *var_len = strlen(tz->country);
            return (u_char *)tz->country;
        }
        *var_len = 0;
        return NULL;
    default:
        break;
    }
    return NULL;
}
Пример #7
0
/*
 * var_interfaces():
 *   This function is called every time the agent gets a request for
 *   a scalar variable that might be found within your mib section
 *   registered above.  It is up to you to do the right thing and
 *   return the correct value.
 *     You should also correct the value of "var_len" if necessary.
 *
 *   Please see the documentation for more information about writing
 *   module extensions, and check out the examples in the examples
 *   and mibII directories.
 */
unsigned char *
var_interfaces(struct variable *vp, 
               oid     *name, 
               size_t  *length, 
               int     exact, 
               size_t  *var_len, 
               WriteMethod **write_method)
{
    

  static long long_ret;
  
  if ( MATCH_FAILED ==
       header_generic(vp,name,length,exact,var_len,write_method) )
    return NULL;
  
  /* 
   * this is where we do the value assignments for the mib results.
   */
  switch(vp->magic) {
  case IFNUMBER: {
    long_ret = cyg_snmp_num_interfaces();
    return (unsigned char *) &long_ret;
  }
  default:
    ERROR_MSG("");
  }
  return NULL;
}
Пример #8
0
static u_char *ast_var_channel_bridge(struct variable *vp, oid *name, size_t *length,
	int exact, size_t *var_len, WriteMethod **write_method)
{
	static unsigned long long_ret;
	struct ast_channel *chan = NULL;
	struct ast_channel_iterator *iter;

	long_ret = 0;

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

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

	while ((chan = ast_channel_iterator_next(iter))) {
		ast_channel_lock(chan);
		if (ast_bridged_channel(chan)) {
			long_ret++;
		}
		ast_channel_unlock(chan);
		chan = ast_channel_unref(chan);
	}

	ast_channel_iterator_destroy(iter);

	*var_len = sizeof(long_ret);

	return (vp->magic == ASTCHANBRIDGECOUNT) ? (u_char *) &long_ret : NULL;
}
u_char         *
var_snmp(struct variable *vp,
         oid * name,
         size_t * length,
         int exact, size_t * var_len, WriteMethod ** write_method)
{
    static long     long_ret;

    *write_method = 0;          /* assume it isnt writable for the time being */
    *var_len = sizeof(long_ret);        /* assume an integer and change later if not */

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

    /*
     * this is where we do the value assignments for the mib results. 
     */
    if (vp->magic == SNMPENABLEAUTHENTRAPS) {
        *write_method = write_snmp;
        long_return = snmp_enableauthentraps;
        return (u_char *) & long_return;
    } else if ((vp->magic >= 1)
               && (vp->magic <=
                   (STAT_SNMP_STATS_END - STAT_SNMP_STATS_START + 1))) {
        long_ret =
            snmp_get_statistic(vp->magic + STAT_SNMP_STATS_START - 1);
        return (unsigned char *) &long_ret;
    }
    return NULL;
}
Пример #10
0
unsigned char *
var_carp_sysctl(struct variable *vp, oid *name, size_t *length, int exact,
		size_t *var_len, WriteMethod **write_method)
{
	int index, v;
	static u_long ulong_ret;

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

	index = name[*length-2];

	switch(vp->magic) {
		case CARP_SYSCTL1:
		case CARP_SYSCTL2:
		case CARP_SYSCTL3:
			if ((v = carp_sysctl_get(index)) == -1)
				return (NULL);
			ulong_ret = v ? 1 : 2;   /* truthvalue */
			break;
		default:
			return (NULL);
	}

	return ((unsigned char *) &ulong_ret);
}
Пример #11
0
/**
 * @fn u_char * var_ss7OmMIB(struct variable *vp, oid *name, size_t *length, int exact, size_t *var_len, WriteMethod **write_method)
 * @param vp a pointer to the entry in the variables table for the requested variable.
 * @param name the object identifier for which to find.
 * @param length the length of the object identifier.
 * @param exact whether the name is exact.
 * @param var_len a pointer to the length of the representation of the object.
 * @param write_method a pointer to a write method for the object.
 * @brief locate variables in ss7OmMIB.
 *
 * This function returns a pointer to a memory area that is static across the request that contains
 * the UCD-SNMP representation of the scalar (so that it may be used to read from for a GET,
 * GET-NEXT or GET-BULK request).  This returned pointer may be NULL, in which case the function is
 * telling UCD-SNMP that the scalar does not exist for reading; however, if write_method is
 * overwritten with a non-NULL value, the function is telling UCD-SNMP that the scalar exists for
 * writing.  Write-only objects can be effected in this way.
 */
u_char *
var_ss7OmMIB(struct variable *vp, oid * name, size_t *length, int exact, size_t *var_len, WriteMethod ** write_method)
{
	struct ss7OmMIB_data *StorageTmp;
	u_char *rval;

	DEBUGMSGTL(("ss7OmMIB", "var_ss7OmMIB: lookup up varbind...  "));
	if (header_generic(vp, name, length, exact, var_len, write_method) == MATCH_FAILED)
		return NULL;
	/* Refresh the MIB values if required. */
	refresh_ss7OmMIB(0);
	if ((StorageTmp = ss7OmMIBStorage) == NULL) {
		DEBUGMSGTL(("ss7OmMIB", "no datastructure.\n"));
		return NULL;
	}
	*write_method = NULL;
	*var_len = 0;
	rval = NULL;
	/* This is where we do the value assignments for the mib results. */
	switch (vp->magic) {
	default:
		ERROR_MSG("");
	}
	if (rval)
		DEBUGMSGTL(("ss7OmMIB", "found.\n"));
	else
		DEBUGMSGTL(("ss7OmMIB", "not found.\n"));
	return (rval);
}
Пример #12
0
/*
 * var_cpqHostOs():
 *   This function is called every time the agent gets a request for
 *   a scalar variable that might be found within your mib section
 *   registered above.  It is up to you to do the right thing and
 *   return the correct value.
 *     You should also correct the value of "var_len" if necessary.
 *
 *   Please see the documentation for more information about writing
 *   module extensions, and check out the examples in the examples
 *   and mibII directories.
 */
unsigned char  *
var_cpqHostOs(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 char string[SPRINT_MAX_LEN];
    int j;

    DEBUGMSGTL(("cpqHostOS", "Handler\n"));

    if (header_generic(vp, name, length, exact, var_len, write_method)
        == MATCH_FAILED)
        return NULL;
    /* prevent struct from changing while we are working with it */

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

    case CPQHO_SWVERAGENTSVER:
        strcpy(string, HELPER_VERSION);
        *var_len = strlen(string);
        return (unsigned char *) string;

    case CPQHO_GENERICDATA:
        strncpy(string, GenericData, sizeof(string) - 1);
        *var_len = strlen(string) + 1;
        return (unsigned char *) string;

    case CPQHO_MIBSTATUSARRAY:
        memcpy(string, &cpqHostMibStatusArray[0],20*sizeof(MibStatusEntry));
        *var_len = 20*sizeof(MibStatusEntry);
        return (unsigned char *) string;

    case CPQHO_MIBHEALTHSTATUSARRAY:
	for (j =  CPQHO_MIBHEALTHSTATUSARRAY_LEN - 1; 
	     (j >= 0) && (cpqHoMibHealthStatusArray[j] == 0);
	     j--) {}
	j++;
	if (j > 0) 
		memcpy(string, cpqHoMibHealthStatusArray, j);
        *var_len = j;
        return (unsigned char *) string;

    default:
        ERROR_MSG("");
    }
    return NULL;
}
Пример #13
0
u_char *var_snmpEngine (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 engineID[SNMP_MAXBUF];

    *write_method = (WriteMethod *) 0;    /* assume it isnt writable for the time being */
    *var_len = sizeof (long_ret);    /* assume an integer and change later if not */

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

    /*
     * this is where we do the value assignments for the mib results. 
     */
    switch (vp->magic)
    {

        case SNMPENGINEID:
            *var_len = snmpv3_get_engineID (engineID, SNMP_MAXBUF);
            /*
             * XXX  Set ERROR_MSG() upon error? 
             */
            return (unsigned char *) engineID;

        case SNMPENGINEBOOTS:
#ifndef NETSNMP_NO_WRITE_SUPPORT
#ifdef NETSNMP_ENABLE_TESTING_CODE
            *write_method = write_engineBoots;
#endif                            /* NETSNMP_ENABLE_TESTING_CODE */
#endif                            /* !NETSNMP_NO_WRITE_SUPPORT */
            long_ret = snmpv3_local_snmpEngineBoots ();
            return (unsigned char *) &long_ret;

        case SNMPENGINETIME:
#ifndef NETSNMP_NO_WRITE_SUPPORT
#ifdef NETSNMP_ENABLE_TESTING_CODE
            *write_method = write_engineTime;
#endif                            /* NETSNMP_ENABLE_TESTING_CODE */
#endif                            /* !NETSNMP_NO_WRITE_SUPPORT */
            long_ret = snmpv3_local_snmpEngineTime ();
            return (unsigned char *) &long_ret;

        case SNMPENGINEMAXMESSAGESIZE:
            long_ret = 1500;
            return (unsigned char *) &long_ret;

        default:
            DEBUGMSGTL (("snmpd", "unknown sub-id %d in var_snmpEngine\n", vp->magic));
    }
    return NULL;
}
Пример #14
0
unsigned char*
var_alarmService(struct variable *vp, 
                oid     *name, 
                size_t  *length, 
                int     exact, 
                size_t  *var_len, 
                WriteMethod **write_method)
{
    
    prop_data properties[KEYS_MAX];
    int prop_count=0;
    static char ap_parameter[256];
	static u_long ulong_ret;
	static long long_ret;
    if( header_generic(vp,name,length,exact,var_len,write_method) == MATCH_FAILED ) 
    {
    	return NULL;
    }
  /* 
   * this is where we do the value assignments for the mib results.
   */
    switch(vp->magic) {
			 case WAPIALARMTIMES:
            *write_method = write_wapialarmtimes;
	    	memset(ap_parameter,0,256);
            prop_count=load_prop(SEP_EQUAL,AG_SNMP_CONF,properties);
            get_prop("ALARM_TIMES",ap_parameter,properties,prop_count);    
	    	free_prop(properties,prop_count) ;
	    	long_ret=atoi(ap_parameter);
	    	//printf("alarm times=%d\n",long_ret);
            return (u_char*) &long_ret ;
  		 case WAPIALARMFLAG:
            *write_method = write_wapialarmflag;
            prop_count=load_prop(SEP_EQUAL,AG_SNMP_CONF,properties);
            get_prop("ALARM_FLAG",ap_parameter,properties,prop_count);
            free_prop(properties,prop_count) ;
            long_ret=atoi(ap_parameter);
            //printf("alarm flag = %d \n ",long_ret);
            return (u_char*) &long_ret ;
       case WAPISTARTSCANAPENABLED:
            *write_method = write_wapiStartScanApEnabled;	  
			long_ret=temp_start_scan_ap_enabled;
            return (u_char*) &long_ret ;
       case WAPIADDNEIGHBORHOODAPMACADDR:
           *write_method = write_wapiAddNeighborhoodApMacAddr;
			memset(ap_parameter,0,256);
			strcpy(ap_parameter,"00:00:00:00:00:00");
			*var_len = strlen(ap_parameter);
	    	ap_parameter[*var_len]='\0'; 
            return (u_char*) ap_parameter ;	
        default:
      		ERROR_MSG("");
    }
  
    return NULL;
}
/******************************************************************
 * hander when access by oid
 *****************************************************************/
unsigned char* var_aj_serial(
    struct variable *vp,
    oid * name,
    size_t * length,
    int exact,
    size_t * var_len,
    WriteMethod ** write_method
)
{
    unsigned long long_ret;

    DEBUGMSGTL(("aj_serial", "var_aj_serial()\n"));
    if(header_generic(vp, name, length, exact, var_len, write_method)
            == MATCH_FAILED) {
        return NULL;
    }

    DEBUGMSGTL(("aj_serial", "magic : %d\n", vp->magic));

    switch(vp->magic) {

    case AJSERICONNECTADDR:
        *write_method = writeConnectAddr;
        return (u_char *)&g_connect_addr;

    case AJSERIPORTNO:
        *write_method = writePortNo;
        return (u_char *)&g_port_no;

    case AJSERISOCKPROTO:
        *write_method = writeSockProto;
        return (u_char *)&g_sock_proto;

    case AJSERIBITRATE:
        *write_method = writeBaudrate;
        return (u_char *)&g_serial_setting.baudrate;

    case AJSERISTOPBIT:
        *write_method = writeStopbit;
        return (u_char *)&g_serial_setting.stop_bit;

    case AJSERIPARITY:
        *write_method = writeParity;
        return (u_char *)&g_serial_setting.parity;

    case AJSERIFLOWCTRL:
        *write_method = writeFlowCtrl;
        return (u_char *)&g_serial_setting.flow_ctrl;

    default:
        DEBUGMSGTL(("aj_serial", "invlid oid%d\n", vp->magic));
        break;
    }
    return NULL;
}
Пример #16
0
u_char         *
var_system(struct variable *vp,
           oid * name,
           size_t * length,
           int exact, size_t * var_len, WriteMethod ** write_method)
{
    static u_long   ulret;

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

    switch (vp->magic) {
    case VERSION_DESCR:
        *var_len = strlen(version_descr);
        return (u_char *) version_descr;
    case VERSIONID:
        *var_len = sysObjectIDLength * sizeof(sysObjectID[0]);
        return (u_char *)sysObjectID;
    case UPTIME:
        ulret = netsnmp_get_agent_uptime();
        return ((u_char *) & ulret);
    case SYSCONTACT:
        *var_len = strlen(sysContact);
        *write_method = writeSystem;
        return (u_char *) sysContact;
    case SYSTEMNAME:
        *var_len = strlen(sysName);
        *write_method = writeSystem;
        return (u_char *) sysName;
    case SYSLOCATION:
        *var_len = strlen(sysLocation);
        *write_method = writeSystem;
        return (u_char *) sysLocation;
    case SYSSERVICES:
#if NETSNMP_NO_DUMMY_VALUES
        if (!sysServicesConfiged)
            return NULL;
#endif
        long_return = sysServices;
        return (u_char *) & long_return;

#ifdef USING_MIBII_SYSORTABLE_MODULE
    case SYSORLASTCHANGE:
        ulret = netsnmp_timeval_uptime(&sysOR_lastchange);
        return ((u_char *) & ulret);
#endif

    default:
        DEBUGMSGTL(("snmpd", "unknown sub-id %d in var_system\n",
                    vp->magic));
    }
    return NULL;
}
Пример #17
0
unsigned char  *
var_ucdDemoPublic(struct variable *vp,
                  oid * name,
                  size_t * length,
                  int exact, size_t * var_len, WriteMethod ** write_method)
{
    static long     long_ret;
    static char     string[MYMAX + 1], *cp;
    int             i;

    *write_method = 0;          /* assume it isnt writable for the time being */
    *var_len = sizeof(long_ret);        /* assume an integer and change later if not */

    if (header_generic(vp, name, length, exact, var_len, write_method))
        return 0;

    /*
     * this is where we do the value assignments for the mib results. 
     */
    switch (vp->magic) {

    case UCDDEMORESETKEYS:
        *write_method = write_ucdDemoResetKeys;
        long_ret = 0;
        return (unsigned char *) &long_ret;

    case UCDDEMOPUBLICSTRING:
        *write_method = write_ucdDemoPublicString;
        *var_len = strlen(publicString);
        return (unsigned char *) publicString;

    case UCDDEMOUSERLIST:
        cp = string;
        for (i = 0; i < num; i++) {
            snprintf(cp, sizeof(string)-strlen(string), " %s", demoUsers[i]);
            string[MYMAX] = 0;
            cp = cp + strlen(cp);
        }
        *var_len = strlen(string);
        return (unsigned char *) string;

    case UCDDEMOPASSPHRASE:
        *var_len = strlen(demopass);
        return (unsigned char *) demopass;

    default:
        DEBUGMSGTL(("snmpd", "unknown sub-id %d in var_ucdDemoPublic\n",
                    vp->magic));
    }
    return 0;
}
Пример #18
0
static u_char*
snmp_scalar(struct variable *vp, oid *name, size_t *length,
		 int exact, size_t *var_len, WriteMethod **write_method)
{
	static unsigned long long_ret;
	static char version[] = VERSION_STRING;

	if (header_generic(vp, name, length, exact, var_len, write_method))
		return NULL;
	
	switch (vp->magic) {
	case SNMP_KEEPALIVEDVERSION:
		*var_len = sizeof(version) - 2;
		return (u_char *)version;
	case SNMP_ROUTERID:
		if (!data->router_id) return NULL;
		*var_len = strlen(data->router_id);
		return (u_char *)data->router_id;
	case SNMP_MAIL_SMTPSERVERADDRESSTYPE:
		long_ret = (data->smtp_server.ss_family == AF_INET6)?2:1;
		return (u_char *)&long_ret;
	case SNMP_MAIL_SMTPSERVERADDRESS:
		if (data->smtp_server.ss_family == AF_INET6) {
			struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)&data->smtp_server;
			*var_len = 16;
			return (u_char *)&addr6->sin6_addr;
		} else {
			struct sockaddr_in *addr4 = (struct sockaddr_in *)&data->smtp_server;
			*var_len = 4;
			return (u_char *)&addr4->sin_addr;
		}
		return NULL;
	case SNMP_MAIL_SMTPSERVERTIMEOUT:
		long_ret = data->smtp_connection_to / TIMER_HZ;
		return (u_char *)&long_ret;
	case SNMP_MAIL_EMAILFROM:
		if (!data->email_from) return NULL;
		*var_len = strlen(data->email_from);
		return (u_char *)data->email_from;
	case SNMP_TRAPS:
		long_ret = data->enable_traps?1:2;
		return (u_char *)&long_ret;
	case SNMP_LINKBEAT:
		long_ret = data->linkbeat_use_polling?2:1;
		return (u_char *)&long_ret;
	default:
		break;
	}
	return NULL;
}
Пример #19
0
static u_char *ast_var_Modules(struct variable *vp, oid *name, size_t *length,
							  int exact, size_t *var_len, WriteMethod **write_method)
{
	static unsigned long long_ret;

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

	if (vp->magic != ASTMODCOUNT)
		return NULL;

	long_ret = ast_update_module_list(countmodule, NULL);

	return (u_char *)&long_ret;
}
Пример #20
0
static u_char *
ast_var_channels(struct variable *vp, oid *name, size_t *length,
				 int exact, size_t *var_len, WriteMethod **write_method)
{
	static unsigned long long_ret;

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

	if (vp->magic != ASTCHANCOUNT)
		return NULL;

	long_ret = ast_active_channels();

	return (u_char *)&long_ret;
}
Пример #21
0
static u_char *ast_var_channel_types(struct variable *vp, oid *name, size_t *length,
								   int exact, size_t *var_len, WriteMethod **write_method)
{
	static unsigned long long_ret;
	struct ast_variable *channel_types, *next;

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

	if (vp->magic != ASTCHANTYPECOUNT)
		return NULL;

	for (long_ret = 0, channel_types = next = ast_channeltype_list(); next; next = next->next)
		long_ret++;
	ast_variables_destroy(channel_types);

	return (u_char *)&long_ret;
}
Пример #22
0
/*
 * var_parentalControl():
 *   This function is called every time the agent gets a request for
 *   a scalar variable that might be found within your mib section
 *   registered above.  It is up to you to do the right thing and
 *   return the correct value.
 *     You should also correct the value of "var_len" if necessary.
 *
 *   Please see the documentation for more information about writing
 *   module extensions, and check out the examples in the examples
 *   and mibII directories.
 */
unsigned char *
var_parentalControl(struct variable *vp, 
                oid     *name, 
                size_t  *length, 
                int     exact, 
                size_t  *var_len, 
                WriteMethod **write_method)
{
    /* variables we may use later */

    if(sw_mode == SW_MODE_AP || sw_mode == SW_MODE_REPEATER)  //Doesn't support in AP and repeater mode
    return NULL;

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

    /* 
   * this is where we do the value assignments for the mib results.
   */
    switch(vp->magic) {
    case PCONTROLENABLE:
        *write_method = write_pControlEnable;
        if(nmp_safe_get("MULTIFILTER_ALL")!=NULL)
        {
            tmpval = nmp_get_int("MULTIFILTER_ALL");
            if(tmpval == 0) /* off */
                tmpval = 2;
            *var_len = sizeof( long );
            return ( u_char * ) &tmpval;            
        }
        return NULL;
    case PCONTROLSCANCLIENTS:
        *write_method = write_pControlScanClients;
        tmpval = 2; /* nothing */
        *var_len = sizeof( long );
        return ( u_char * ) &tmpval;
    default:
      ERROR_MSG("");
    }
    return NULL;
}
Пример #23
0
static u_char *ast_var_Version(struct variable *vp, oid *name, size_t *length,
                               int exact, size_t *var_len, WriteMethod **write_method)
{
    static unsigned long long_ret;

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

    switch (vp->magic) {
    case ASTVERSTRING:
        *var_len = strlen(ASTERISK_VERSION);
        return (u_char *)ASTERISK_VERSION;
    case ASTVERTAG:
        long_ret = ASTERISK_VERSION_NUM;
        return (u_char *)&long_ret;
    default:
        break;
    }
    return NULL;
}
Пример #24
0
static u_char *ast_var_channel_bridge(struct variable *vp, oid *name, size_t *length,
	int exact, size_t *var_len, WriteMethod **write_method)
{
	static unsigned long long_ret;
	struct ast_channel *chan = NULL;

	long_ret = 0;
	if (header_generic(vp, name, length, exact, var_len, write_method))
		return NULL;

	while ((chan = ast_channel_walk_locked(chan))) {
		if (ast_bridged_channel(chan))
			long_ret++;
		ast_channel_unlock(chan);
	}

	*var_len = sizeof(long_ret);

	return (vp->magic == ASTCHANBRIDGECOUNT) ? (u_char *) &long_ret : NULL;
}
Пример #25
0
static u_char *ast_var_indications(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[128];
	struct ast_tone_zone *tz = NULL;

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

	switch (vp->magic) {
	case ASTINDCOUNT:
	{
		struct ao2_iterator i;

		long_ret = 0;

		i = ast_tone_zone_iterator_init();
		while ((tz = ao2_iterator_next(&i))) {
			tz = ast_tone_zone_unref(tz);
			long_ret++;
		}
		ao2_iterator_destroy(&i);

		return (u_char *) &long_ret;
	}
	case ASTINDCURRENT:
		tz = ast_get_indication_zone(NULL);
		if (tz) {
			ast_copy_string(ret_buf, tz->country, sizeof(ret_buf));
			*var_len = strlen(ret_buf);
			tz = ast_tone_zone_unref(tz);
			return (u_char *) ret_buf;
		}
		*var_len = 0;
		return NULL;
	default:
		break;
	}
	return NULL;
}
Пример #26
0
/*
 * var_cyrusMasterMIB():
 *   This function is called every time the agent gets a request for
 *   a scalar variable that might be found within your mib section
 *   registered above.  It is up to you to do the right thing and
 *   return the correct value.
 *     You should also correct the value of "var_len" if necessary.
 *
 *   Please see the documentation for more information about writing
 *   module extensions, and check out the examples in the examples
 *   and mibII directories.
 */
unsigned char *
var_cyrusMasterMIB(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 char string[SPRINT_MAX_LEN];
    /* static oid objid[MAX_OID_LEN]; */
    /* static struct counter64 c64; */

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

    /* 
     * this is where we do the value assignments for the mib results.
     */
    switch(vp->magic) {
    case CYRUSMASTERINFODESCR:
	strlcpy(string, "Cyrus IMAP server master process", sizeof(string));
	*var_len = strlen(string);
	return (unsigned char *) string;
      
    case CYRUSMASTERINFOVERS:
	strlcpy(string, _CYRUS_VERSION, sizeof(string));
	*var_len = strlen(string);
	return (unsigned char *) string;
      
    case CYRUSMASTERINFOUPTIME:
	long_ret = 100 * (time(NULL) - startTime);
	return (unsigned char *) &long_ret;
      
    default:
	ERROR_MSG("");
    }
    return NULL;
}
Пример #27
0
/*
 * var_extensible_errors(...
 * Arguments:
 * vp     IN      - pointer to variable entry that points here
 * name    IN/OUT  - IN/name requested, OUT/name found
 * length  IN/OUT  - length of IN/OUT oid's 
 * exact   IN      - TRUE if an exact match was requested
 * var_len OUT     - length of variable or 0 if function returned
 * write_method
 * 
 */
u_char         *
var_extensible_errors(struct variable *vp,
                      oid * name,
                      size_t * length,
                      int exact,
                      size_t * var_len, WriteMethod ** write_method)
{

    static long     long_ret;
    static char     errmsg[300];


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

    errmsg[0] = 0;

    switch (vp->magic) {
    case MIBINDEX:
        long_ret = name[*length - 1];
        return ((u_char *) (&long_ret));
    case ERRORNAME:
        strcpy(errmsg, "snmp");
        *var_len = strlen(errmsg);
        return ((u_char *) errmsg);
    case ERRORFLAG:
        long_ret =
            (NETSNMP_ERRORTIMELENGTH >= time(NULL) - errorstatustime) ? 1 : 0;
        return ((u_char *) (&long_ret));
    case ERRORMSG:
        if ((NETSNMP_ERRORTIMELENGTH >= time(NULL) - errorstatustime) ? 1 : 0) {
            strncpy(errmsg, errorstring, sizeof(errmsg));
            errmsg[ sizeof(errmsg)-1 ] = 0;
        } else
            errmsg[0] = 0;
        *var_len = strlen(errmsg);
        return ((u_char *) errmsg);
    }
    return NULL;
}
Пример #28
0
static u_char *ast_var_channel_types(struct variable *vp, oid *name, size_t *length,
                                     int exact, size_t *var_len, WriteMethod **write_method)
{
    static unsigned long long_ret;
    struct ast_variable *channel_types, *next;

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

    switch (vp->magic) {
    case ASTCHANTYPECOUNT:
        long_ret = 0;
        for (channel_types = next = ast_channeltype_list(); next; next = next->next) {
            long_ret++;
        }
        ast_variables_destroy(channel_types);
        return (u_char *)&long_ret;
    default:
        break;
    }
    return NULL;
}
Пример #29
0
unsigned char *
var_sensors(struct variable *vp, oid *name, size_t *length, int exact,
		size_t *var_len, WriteMethod **write_method)
{
	static u_long ulong_ret;

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

	sensor_refresh();

	switch(vp->magic) {
		case SENS_NUMBER:
			ulong_ret = num_sensors;
			break;
		default:
			return (NULL);
	}

	return ((unsigned char *) &ulong_ret);
}
Пример #30
0
static u_char *ast_var_Version(struct variable *vp, oid *name, size_t *length,
							  int exact, size_t *var_len, WriteMethod **write_method)
{
	static unsigned long long_ret;

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

	switch (vp->magic) {
	case ASTVERSTRING:
	{
		const char *version = ast_get_version();
		*var_len = strlen(version);
		return (u_char *)version;
	}
	case ASTVERTAG:
		sscanf(ast_get_version_num(), "%30lu", &long_ret);
		return (u_char *)&long_ret;
	default:
		break;
	}
	return NULL;
}