/******************************************************************************
 *                                                                            *
 * Function: execute_script                                                   *
 *                                                                            *
 * Purpose: executing command                                                 *
 *                                                                            *
 * Parameters:                                                                *
 *                                                                            *
 * Return value:  SUCCEED - processed successfully                            *
 *                FAIL - an error occurred                                    *
 *                                                                            *
 * Author: Alexander Vladishev                                                *
 *                                                                            *
 * Comments:                                                                  *
 *                                                                            *
 ******************************************************************************/
static int	execute_script(zbx_uint64_t scriptid, zbx_uint64_t hostid, char **result)
{
	const char	*__function_name = "execute_script";
	char		error[MAX_STRING_LEN];
	int		ret = FAIL, rc;
	DC_HOST		host;
	DB_RESULT	db_result;
	DB_ROW		db_row;
	zbx_script_t	script;

	zabbix_log(LOG_LEVEL_DEBUG, "In %s() scriptid:" ZBX_FS_UI64 " hostid:" ZBX_FS_UI64,
			__function_name, scriptid, hostid);

	*error = '\0';

	if (SUCCEED != (rc = DCget_host_by_hostid(&host, hostid)))
	{
		/* let's try to get a host from a database (the host can be disabled) */
		db_result = DBselect("select host,name from hosts where hostid=" ZBX_FS_UI64, hostid);

		if (NULL != (db_row = DBfetch(db_result)))
		{
			memset(&host, 0, sizeof(host));
			host.hostid = hostid;
			strscpy(host.host, db_row[0]);
			strscpy(host.name, db_row[1]);

			rc = SUCCEED;
		}
		DBfree_result(db_result);
	}

	if (SUCCEED != rc)
	{
		zbx_snprintf(error, sizeof(error), "Unknown Host ID [" ZBX_FS_UI64 "]", hostid);
		goto fail;
	}

	zbx_script_init(&script);

	script.type = ZBX_SCRIPT_TYPE_GLOBAL_SCRIPT;
	script.scriptid = scriptid;

	ret = zbx_execute_script(&host, &script, result, error, sizeof(error));

	zbx_script_clean(&script);
fail:
	if (SUCCEED != ret)
	{
		if (0 != CONFIG_NODEID)
			*result = zbx_dsprintf(*result, "NODE %d: %s", CONFIG_NODEID, error);
		else
			*result = zbx_strdup(*result, error);
	}

	zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret));

	return ret;
}
Beispiel #2
0
int	CHECK_DNS(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_RES_QUERY

#if !defined(PACKETSZ)
#	define PACKETSZ 512
#endif /* PACKETSZ */

#if !defined(C_IN)
#	define C_IN	ns_c_in
#endif /* C_IN */

#if !defined(T_ANY)
#	define T_ANY	ns_t_any
#endif /* T_ANY */

	int		res;
	char		ip[MAX_STRING_LEN];
	char		zone[MAX_STRING_LEN];
#ifdef	PACKETSZ
	unsigned char	respbuf[PACKETSZ];
#else
	unsigned char	respbuf[NS_PACKETSZ];
#endif

	assert(result);

	init_result(result);

	if (num_param(param) > 2)
		return SYSINFO_RET_FAIL;

	if (0 != get_param(param, 1, ip, MAX_STRING_LEN))
               *ip = '\0';

	/* default parameter */
	if (*ip == '\0')
		strscpy(ip, "127.0.0.1");

	if (0 != get_param(param, 2, zone, MAX_STRING_LEN))
		*zone = '\0';

	/* default parameter */
	if (*zone == '\0')
		strscpy(zone, "localhost");

	if (!(_res.options & RES_INIT))
		res_init();

	res = res_query(zone, C_IN, T_ANY, respbuf, sizeof(respbuf));

	SET_UI64_RESULT(result, res != -1 ? 1 : 0);

	return SYSINFO_RET_OK;
#endif /* HAVE_RES_QUERY */

	return SYSINFO_RET_FAIL;
}
Beispiel #3
0
static int vidioc_venc_querycap(struct file *file, void *priv,
				struct v4l2_capability *cap)
{
	strscpy(cap->driver, MTK_VCODEC_ENC_NAME, sizeof(cap->driver));
	strscpy(cap->bus_info, MTK_PLATFORM_STR, sizeof(cap->bus_info));
	strscpy(cap->card, MTK_PLATFORM_STR, sizeof(cap->card));

	return 0;
}
Beispiel #4
0
int topic_replace_prepend(User * u, Channel *c, char *newtopic) {
	char topic[1024], buf[1024], *mtopic;
	ChannelInfo *ci = c->ci;

	if (ci->flags & CI_VERBOTEN) {
		notice_lang(ci->bi->nick, u, CHAN_X_FORBIDDEN, ci->name);
		return MOD_STOP;
	}

	if (!my_check_access(u, ci, CA_TOPIC) && ((ci->flags & CI_TOPICLOCK) || !my_check_access(u, ci, CA_OPDEOPME))) {
		notice_lang(ci->bi->nick, u, PERMISSION_DENIED);
		return MOD_STOP;
	}

	memset(topic, 0, 1024);
	if (ci->last_topic) {
		/* Copy topic starting after the first delimiter.. */
		mtopic = strstr(ci->last_topic, (AppendToTopicDel ? AppendToTopicDel : "||"));
		if (mtopic) {
			memset(buf, 0, 1024);
			strcat(buf, mtopic + strlen((AppendToTopicDel ? AppendToTopicDel : "||")));

			if (newtopic)
				snprintf(topic, sizeof(topic), "%s %s%s", newtopic,
						(AppendToTopicDel ? AppendToTopicDel : "||"), buf);
			else
				snprintf(topic, sizeof(topic), "%s", buf);
		} else
			snprintf(topic, sizeof(topic), "%s %s %s", newtopic,
					(AppendToTopicDel ? AppendToTopicDel : "||"), ci->last_topic);
	} else if (newtopic)
		strcpy(topic, newtopic);

	ci->last_topic = *topic ? sstrdup(topic) : NULL;
	strscpy(ci->last_topic_setter, u->nick, NICKMAX);
	ci->last_topic_time = time(NULL);

	if (c->topic) free(c->topic);
	c->topic = *topic ? sstrdup(topic) : NULL;
	strscpy(c->topic_setter, u->nick, NICKMAX);

	if (ircd->topictsbackward) {
		c->topic_time = c->topic_time - 1;
	} else {
		c->topic_time = ci->last_topic_time;
	}

	if (is_services_admin(u) && !check_access(u, ci, CA_TOPIC) &&
			((ci->flags & CI_TOPICLOCK) || !check_access(u, ci, CA_OPDEOPME)))
		alog("%s: %s!%[email protected]%s changed topic of %s as services admin.",
			ci->bi->nick, u->nick, u->username, u->host, c->name);

	anope_cmd_topic(ci->bi->nick, c->name, u->nick, topic, c->topic_time);

	return MOD_CONT;
}
Beispiel #5
0
/* handle "[<SUBSYSTEM>/<KERNEL>]<attribute>" format */
int util_resolve_subsys_kernel(const char *string, char *result, size_t maxsize, bool read_value) {
        char temp[UTIL_PATH_SIZE], *subsys, *sysname, *attr;
        _cleanup_(sd_device_unrefp) sd_device *dev = NULL;
        const char *val;
        int r;

        if (string[0] != '[')
                return -EINVAL;

        strscpy(temp, sizeof(temp), string);

        subsys = &temp[1];

        sysname = strchr(subsys, '/');
        if (!sysname)
                return -EINVAL;
        sysname[0] = '\0';
        sysname = &sysname[1];

        attr = strchr(sysname, ']');
        if (!attr)
                return -EINVAL;
        attr[0] = '\0';
        attr = &attr[1];
        if (attr[0] == '/')
                attr = &attr[1];
        if (attr[0] == '\0')
                attr = NULL;

        if (read_value && !attr)
                return -EINVAL;

        r = sd_device_new_from_subsystem_sysname(&dev, subsys, sysname);
        if (r < 0)
                return r;

        if (read_value) {
                r = sd_device_get_sysattr_value(dev, attr, &val);
                if (r < 0 && r != -ENOENT)
                        return r;
                if (r == -ENOENT)
                        result[0] = '\0';
                else
                        strscpy(result, maxsize, val);
                log_debug("value '[%s/%s]%s' is '%s'", subsys, sysname, attr, result);
        } else {
                r = sd_device_get_syspath(dev, &val);
                if (r < 0)
                        return r;

                strscpyl(result, maxsize, val, attr ? "/" : NULL, attr ?: NULL, NULL);
                log_debug("path '[%s/%s]%s' is '%s'", subsys, sysname, strempty(attr), result);
        }
        return 0;
}
Beispiel #6
0
/******************************************************************************
 *                                                                            *
 * Function: update_triggers                                                  *
 *                                                                            *
 * Purpose: re-calculate and updates values of triggers related to the item   *
 *                                                                            *
 * Parameters: itemid - item to update trigger values for                     *
 *                                                                            *
 * Return value:                                                              *
 *                                                                            *
 * Author: Alexei Vladishev                                                   *
 *                                                                            *
 * Comments:                                                                  *
 *                                                                            *
 ******************************************************************************/
void	update_triggers(zbx_uint64_t itemid)
{
	char	*exp;
	char	error[MAX_STRING_LEN];
	int	exp_value;
	DB_TRIGGER	trigger;
	DB_RESULT	result;
	DB_ROW		row;

	zabbix_log( LOG_LEVEL_DEBUG, "In update_triggers [itemid:" ZBX_FS_UI64 "]",
		itemid);

	result = DBselect("select distinct t.triggerid,t.expression,t.description,t.url,t.comments,t.status,t.value,t.priority,t.type from triggers t,functions f,items i where i.status<>%d and i.itemid=f.itemid and t.status=%d and f.triggerid=t.triggerid and f.itemid=" ZBX_FS_UI64,
		ITEM_STATUS_NOTSUPPORTED,
		TRIGGER_STATUS_ENABLED,
		itemid);

	while((row=DBfetch(result)))
	{
		ZBX_STR2UINT64(trigger.triggerid,row[0]);
		strscpy(trigger.expression,row[1]);
		strscpy(trigger.description,row[2]);
		trigger.url		= row[3];
		trigger.comments	= row[4];
		trigger.status		= atoi(row[5]);
		trigger.value		= atoi(row[6]);
		trigger.priority	= atoi(row[7]);
		trigger.type		= atoi(row[8]);

		exp = strdup(trigger.expression);
		if( evaluate_expression(&exp_value, &exp, &trigger, error, sizeof(error)) != 0 )
		{
			zabbix_log(LOG_LEVEL_WARNING, "Expression [%s] for item [" ZBX_FS_UI64 "][%s] cannot be evaluated: %s",
				trigger.expression,
				itemid,
				zbx_host_key_string(itemid),
				error);
			zabbix_syslog("Expression [%s] for item [" ZBX_FS_UI64 "][%s] cannot be evaluated: %s",
				trigger.expression,
				itemid,
				zbx_host_key_string(itemid),
				error);
/*			DBupdate_trigger_value(&trigger, exp_value, time(NULL), error);*//* We shouldn't update triggervalue if expressions failed */
		}
		else
		{
			DBupdate_trigger_value(&trigger, exp_value, time(NULL), NULL);
		}
		zbx_free(exp);
	}
	DBfree_result(result);
	zabbix_log( LOG_LEVEL_DEBUG, "End update_triggers [" ZBX_FS_UI64 "]",
		itemid);
}
Beispiel #7
0
/**
 * Initialize the value buffers for an OLSRv2 node
 * @param node OLSRv2 node
 */
static void
_initialize_node_values(struct olsrv2_tc_node *node) {
  netaddr_to_string(&_value_node, &node->target.prefix.dst);

  oonf_clock_toIntervalString(&_value_node_vtime, oonf_timer_get_due(&node->_validity_time));

  snprintf(_value_node_ansn, sizeof(_value_node_ansn), "%u", node->ansn);

  strscpy(_value_node_virtual, json_getbool(!oonf_timer_is_active(&node->_validity_time)), sizeof(_value_node_virtual));
  strscpy(_value_node_neighbor, json_getbool(node->direct_neighbor), sizeof(_value_node_neighbor));
}
Beispiel #8
0
int
calculate_if_metric(char *ifname)
{
  if (check_wireless_interface(ifname)) {
    struct ifreq ifr;
    strscpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));

    /* Get bit rate */
    if (ioctl(olsr_cnf->ioctl_s, SIOCGIWRATE, &ifr) < 0) {
      OLSR_PRINTF(1, "Not able to find rate for WLAN interface %s\n", ifname);
      return WEIGHT_WLAN_11MB;
    }

    OLSR_PRINTF(1, "Bitrate %d\n", ifr.ifr_ifru.ifru_ivalue);

    //WEIGHT_WLAN_LOW,          /* <11Mb WLAN     */
    //WEIGHT_WLAN_11MB,         /* 11Mb 802.11b   */
    //WEIGHT_WLAN_54MB,         /* 54Mb 802.11g   */
    return WEIGHT_WLAN_LOW;
  } else {
    /* Ethernet */
    /* Mii wizardry */
    struct ifreq ifr;
    struct mii_data *mii = (struct mii_data *)&ifr.ifr_data;
    int bmcr;
    memset(&ifr, 0, sizeof(ifr));
    strscpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));

    if (ioctl(olsr_cnf->ioctl_s, SIOCGMIIPHY, &ifr) < 0) {
      if (errno != ENODEV)
        OLSR_PRINTF(1, "SIOCGMIIPHY on '%s' failed: %s\n", ifr.ifr_name, strerror(errno));
      return WEIGHT_ETHERNET_DEFAULT;
    }

    mii->reg_num = MII_BMCR;
    if (ioctl(olsr_cnf->ioctl_s, SIOCGMIIREG, &ifr) < 0) {
      OLSR_PRINTF(1, "SIOCGMIIREG on %s failed: %s\n", ifr.ifr_name, strerror(errno));
      return WEIGHT_ETHERNET_DEFAULT;
    }
    bmcr = mii->val_out;

    OLSR_PRINTF(1, "%s: ", ifr.ifr_name);
    OLSR_PRINTF(1, "%s Mbit, %s duplex\n", (bmcr & MII_BMCR_100MBIT) ? "100" : "10", (bmcr & MII_BMCR_DUPLEX) ? "full" : "half");

    is_if_link_up(ifname);

    if (mii->val_out & MII_BMCR_100MBIT)
      return WEIGHT_ETHERNET_100MB;
    else
      return WEIGHT_ETHERNET_10MB;
    //WEIGHT_ETHERNET_1GB,      /* Ethernet 1Gb   */

  }
}
Beispiel #9
0
static int cpia2_querycap(struct file *file, void *fh, struct v4l2_capability *vc)
{
	struct camera_data *cam = video_drvdata(file);

	strscpy(vc->driver, "cpia2", sizeof(vc->driver));

	if (cam->params.pnp_id.product == 0x151)
		strscpy(vc->card, "QX5 Microscope", sizeof(vc->card));
	else
		strscpy(vc->card, "CPiA2 Camera", sizeof(vc->card));
	switch (cam->params.pnp_id.device_type) {
	case DEVICE_STV_672:
		strcat(vc->card, " (672/");
		break;
	case DEVICE_STV_676:
		strcat(vc->card, " (676/");
		break;
	default:
		strcat(vc->card, " (XXX/");
		break;
	}
	switch (cam->params.version.sensor_flags) {
	case CPIA2_VP_SENSOR_FLAGS_404:
		strcat(vc->card, "404)");
		break;
	case CPIA2_VP_SENSOR_FLAGS_407:
		strcat(vc->card, "407)");
		break;
	case CPIA2_VP_SENSOR_FLAGS_409:
		strcat(vc->card, "409)");
		break;
	case CPIA2_VP_SENSOR_FLAGS_410:
		strcat(vc->card, "410)");
		break;
	case CPIA2_VP_SENSOR_FLAGS_500:
		strcat(vc->card, "500)");
		break;
	default:
		strcat(vc->card, "XXX)");
		break;
	}

	if (usb_make_path(cam->dev, vc->bus_info, sizeof(vc->bus_info)) <0)
		memset(vc->bus_info,0, sizeof(vc->bus_info));

	vc->device_caps = V4L2_CAP_VIDEO_CAPTURE |
			   V4L2_CAP_READWRITE |
			   V4L2_CAP_STREAMING;
	vc->capabilities = vc->device_caps |
			   V4L2_CAP_DEVICE_CAPS;

	return 0;
}
Beispiel #10
0
/* find device node of device with highest priority */
static const char *link_find_prioritized(struct udev_device *dev, bool add, const char *stackdir, char *buf, size_t bufsize)
{
        struct udev *udev = udev_device_get_udev(dev);
        DIR *dir;
        int priority = 0;
        const char *target = NULL;

        if (add) {
                priority = udev_device_get_devlink_priority(dev);
                strscpy(buf, bufsize, udev_device_get_devnode(dev));
                target = buf;
        }

        dir = opendir(stackdir);
        if (dir == NULL)
                return target;
        for (;;) {
                struct udev_device *dev_db;
                struct dirent *dent;

                dent = readdir(dir);
                if (dent == NULL || dent->d_name[0] == '\0')
                        break;
                if (dent->d_name[0] == '.')
                        continue;

                log_debug("found '%s' claiming '%s'", dent->d_name, stackdir);

                /* did we find ourself? */
                if (streq(dent->d_name, udev_device_get_id_filename(dev)))
                        continue;

                dev_db = udev_device_new_from_device_id(udev, dent->d_name);
                if (dev_db != NULL) {
                        const char *devnode;

                        devnode = udev_device_get_devnode(dev_db);
                        if (devnode != NULL) {
                                if (target == NULL || udev_device_get_devlink_priority(dev_db) > priority) {
                                        log_debug("'%s' claims priority %i for '%s'",
                                                  udev_device_get_syspath(dev_db), udev_device_get_devlink_priority(dev_db), stackdir);
                                        priority = udev_device_get_devlink_priority(dev_db);
                                        strscpy(buf, bufsize, devnode);
                                        target = buf;
                                }
                        }
                        udev_device_unref(dev_db);
                }
        }
        closedir(dir);
        return target;
}
Beispiel #11
0
static int radio_isa_querycap(struct file *file, void  *priv,
					struct v4l2_capability *v)
{
	struct radio_isa_card *isa = video_drvdata(file);

	strscpy(v->driver, isa->drv->driver.driver.name, sizeof(v->driver));
	strscpy(v->card, isa->drv->card, sizeof(v->card));
	snprintf(v->bus_info, sizeof(v->bus_info), "ISA:%s", isa->v4l2_dev.name);

	v->device_caps = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
	v->capabilities = v->device_caps | V4L2_CAP_DEVICE_CAPS;
	return 0;
}
Beispiel #12
0
static int gsc_m2m_querycap(struct file *file, void *fh,
			   struct v4l2_capability *cap)
{
	struct gsc_ctx *ctx = fh_to_ctx(fh);
	struct gsc_dev *gsc = ctx->gsc_dev;

	strscpy(cap->driver, GSC_MODULE_NAME, sizeof(cap->driver));
	strscpy(cap->card, GSC_MODULE_NAME " gscaler", sizeof(cap->card));
	snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s",
		 dev_name(&gsc->pdev->dev));
	cap->device_caps = V4L2_CAP_STREAMING | V4L2_CAP_VIDEO_M2M_MPLANE;
	cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
	return 0;
}
Beispiel #13
0
/**
 * do initialization
 */
void
name_constructor(void) 
{
	int i;
	
#ifdef WIN32
	int len;

	GetWindowsDirectory(my_hosts_file, MAX_FILE - 12);
	GetWindowsDirectory(my_services_file, MAX_FILE - 12);
	GetWindowsDirectory(my_resolv_file, MAX_FILE - 12);

	len = strlen(my_hosts_file);
	if (my_hosts_file[len - 1] != '\\')
		strscat(my_hosts_file, "\\", sizeof(my_host_file));
	strscat(my_hosts_file, "hosts_olsr", sizeof(my_host_file));
	
	len = strlen(my_services_file);
	if (my_services_file[len - 1] != '\\')
		strscat(my_services_file, "\\", sizeof(my_services_file));
	strscat(my_services_file, "services_olsr", sizeof(my_services_file));

	len = strlen(my_resolv_file);
	if (my_resolv_file[len - 1] != '\\')
		strscat(my_resolv_file, "\\", sizeof(my_resolv_file));
	strscat(my_resolv_file, "resolvconf_olsr", sizeof(my_resolv_file));
#else
	strscpy(my_hosts_file, "/var/run/hosts_olsr", sizeof(my_hosts_file));
	strscpy(my_services_file, "/var/run/services_olsr", sizeof(my_services_file));
	strscpy(my_resolv_file, "/var/run/resolvconf_olsr", sizeof(my_resolv_file));
	*my_sighup_pid_file = 0;
#endif

	my_suffix[0] = '\0';
	my_add_hosts[0] = '\0';
	my_latlon_file[0] = '\0';
	latlon_in_file[0] = '\0';
	my_name_change_script[0] = '\0';
	my_services_change_script[0] = '\0';
	
	/* init the lists heads */
	for(i = 0; i < HASHSIZE; i++) {
		list_head_init(&name_list[i]);
		list_head_init(&forwarder_list[i]);
		list_head_init(&service_list[i]);
		list_head_init(&latlon_list[i]);
	}
	

}
Beispiel #14
0
int append_to_topic(User * u, Channel *c, char *newtopic) {
	char topic[1024];
	ChannelInfo *ci = c->ci;

	if (!newtopic) {
		noticeLang(ci->bi->nick, u, LANG_APPENDT_SYNTAX);
		return MOD_STOP;
	}

	if (ci->flags & CI_VERBOTEN) {
		notice_lang(ci->bi->nick, u, CHAN_X_FORBIDDEN, ci->name);
		return MOD_STOP;
	}

	if (!my_check_access(u, ci, CA_TOPIC) && ((ci->flags & CI_TOPICLOCK) || !my_check_access(u, ci, CA_OPDEOPME))) {
		notice_lang(ci->bi->nick, u, PERMISSION_DENIED);
		return MOD_STOP;
	}

	if (ci->last_topic) {
		snprintf(topic, sizeof(topic), "%s %s %s", ci->last_topic,
			(AppendToTopicDel ? AppendToTopicDel : "||"), newtopic);
		free(ci->last_topic);
	} else
		strcpy(topic, newtopic);

	ci->last_topic = *topic ? sstrdup(topic) : NULL;
	strscpy(ci->last_topic_setter, u->nick, NICKMAX);
	ci->last_topic_time = time(NULL);

	if (c->topic) free(c->topic);
	c->topic = *topic ? sstrdup(topic) : NULL;
	strscpy(c->topic_setter, u->nick, NICKMAX);

	if (ircd->topictsbackward) {
		c->topic_time = c->topic_time - 1;
	} else {
		c->topic_time = ci->last_topic_time;
	}

	if (is_services_admin(u) && !check_access(u, ci, CA_TOPIC) &&
			((ci->flags & CI_TOPICLOCK) || !check_access(u, ci, CA_OPDEOPME)))
		alog("%s: %s!%[email protected]%s changed topic of %s as services admin.",
			ci->bi->nick, u->nick, u->username, u->host, c->name);

	anope_cmd_topic(ci->bi->nick, c->name, u->nick, topic, c->topic_time);

	return MOD_CONT;
}
Beispiel #15
0
int	NET_IF_TOTAL(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
	const MODE_FUNCTION	fl[] =
	{
		{"bytes",   NET_IF_TOTAL_BYTES},
		{"packets", NET_IF_TOTAL_PACKETS},
		{"errors",  NET_IF_TOTAL_ERRORS},
		{NULL,	    0}
	};

	char	if_name[MAX_STRING_LEN], mode[16];
	int	i;

	if (2 < num_param(param))
		return SYSINFO_RET_FAIL;

	if (0 != get_param(param, 1, if_name, sizeof(if_name)))
		return SYSINFO_RET_FAIL;

	if (0 != get_param(param, 2, mode, sizeof(mode)) || '\0' == *mode)
		strscpy(mode, "bytes");

	for (i = 0; NULL != fl[i].mode; i++)
		if (0 == strcmp(mode, fl[i].mode))
			return (fl[i].function)(if_name, result);

	return SYSINFO_RET_FAIL;
}
Beispiel #16
0
static User *new_user(const char *nick)
{
    User *user, **list;

    user = scalloc(sizeof(User), 1);
    if (!nick)
        nick = "";
    strscpy(user->nick, nick, NICKMAX);
    list = &userlist[HASH(user->nick)];
    user->next = *list;
    if (*list)
        (*list)->prev = user;
    *list = user;
    user->na = findnick(nick);
    if (user->na)
        user->na->u = user;
    usercnt++;
    if (usercnt > maxusercnt) {
        maxusercnt = usercnt;
        maxusertime = time(NULL);
        if (LogMaxUsers)
            alog("user: New maximum user count: %d", maxusercnt);
    }
    user->isSuperAdmin = 0;     /* always set SuperAdmin to 0 for new users */
    user->nickTrack = NULL;     /* ensure no default tracking nick */
    return user;
}
Beispiel #17
0
char	*get_ip_by_socket(zbx_sock_t *s)
{
	ZBX_SOCKADDR	sa;
	ZBX_SOCKLEN_T	sz = sizeof(sa);
	static char	host[64];
	char		*error_message = NULL;

	if (ZBX_TCP_ERROR == getpeername(s->socket, (struct sockaddr*)&sa, &sz))
	{
		error_message = strerror_from_system(zbx_sock_last_error());
		zbx_set_tcp_strerror("connection rejected, getpeername() failed: %s", error_message);
		goto out;
	}

#if defined(HAVE_IPV6)
	if (0 != zbx_getnameinfo((struct sockaddr *)&sa, host, sizeof(host), NULL, 0, NI_NUMERICHOST))
	{
		error_message = strerror_from_system(zbx_sock_last_error());
		zbx_set_tcp_strerror("connection rejected, getnameinfo() failed: %s", error_message);
	}
#else
	zbx_snprintf(host, sizeof(host), "%s", inet_ntoa(sa.sin_addr));
#endif

out:
	if (NULL != error_message)
	{
		zabbix_log(LOG_LEVEL_WARNING, "Cannot get socket IP address: %s", error_message);
		strscpy(host, "unknown IP");
	}

	return host;
}
static int set_usb_mass_storage_ifsubtype(char *to, const char *from, size_t len) {
        int type_num = 0;
        char *eptr;
        const char *type = "generic";

        type_num = strtoul(from, &eptr, 0);
        if (eptr != from) {
                switch (type_num) {
                case 1: /* RBC devices */
                        type = "rbc";
                        break;
                case 2:
                        type = "atapi";
                        break;
                case 3:
                        type = "tape";
                        break;
                case 4: /* UFI */
                        type = "floppy";
                        break;
                case 6: /* Transparent SPC-2 devices */
                        type = "scsi";
                        break;
                default:
                        break;
                }
        }
        strscpy(to, len, type);
        return type_num;
}
Beispiel #19
0
int	NET_TCP_PORT(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
	unsigned short	port;
	int		value_int, ret;
	char		ip[64], port_str[8];

	if (2 < num_param(param))
		return SYSINFO_RET_FAIL;

	if (0 != get_param(param, 1, ip, sizeof(ip)))
		*ip = '\0';

	if ('\0' == *ip)
		strscpy(ip, "127.0.0.1");

	if (0 != get_param(param, 2, port_str, sizeof(port_str)))
		*port_str = '\0';

	if (SUCCEED != is_ushort(port_str, &port))
		return SYSINFO_RET_FAIL;

	if (SYSINFO_RET_OK == (ret = tcp_expect(ip, port, CONFIG_TIMEOUT, NULL, NULL, NULL, &value_int)))
		SET_UI64_RESULT(result, value_int);

	return ret;
}
Beispiel #20
0
int	VM_MEMORY_SIZE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef HAVE_LIBPERFSTAT
	const MODE_FUNCTION	fl[] =
	{
		{"total",	VM_MEMORY_TOTAL},
		{"pinned",	VM_MEMORY_PINNED},
		{"free",	VM_MEMORY_FREE},
		{"used",	VM_MEMORY_USED},
		{"pused",	VM_MEMORY_PUSED},
		{"available",	VM_MEMORY_AVAILABLE},
		{"pavailable",	VM_MEMORY_PAVAILABLE},
		{"cached",	VM_MEMORY_CACHED},
		{NULL,		0}
	};

	char	mode[MAX_STRING_LEN];
	int	i;

	if (1 < num_param(param))
		return SYSINFO_RET_FAIL;

	if (0 != get_param(param, 1, mode, sizeof(mode)) || '\0' == *mode)
		strscpy(mode, "total");

	for (i = 0; NULL != fl[i].mode; i++)
		if (0 == strcmp(mode, fl[i].mode))
			return (fl[i].function)(result);
#endif
	return SYSINFO_RET_FAIL;
}
Beispiel #21
0
static void set_type(const char *from, char *to, size_t len) {
        int type_num;
        char *eptr;
        const char *type = "generic";

        type_num = strtoul(from, &eptr, 0);
        if (eptr != from) {
                switch (type_num) {
                case 0:
                        type = "disk";
                        break;
                case 1:
                        type = "tape";
                        break;
                case 4:
                        type = "optical";
                        break;
                case 5:
                        type = "cd";
                        break;
                case 7:
                        type = "optical";
                        break;
                case 0xe:
                        type = "disk";
                        break;
                case 0xf:
                        type = "optical";
                        break;
                default:
                        break;
                }
        }
        strscpy(to, len, type);
}
Beispiel #22
0
/*
 ****************************************************************
 *	Insere os símbolos, enquanto não há colisão		*
 ****************************************************************
 */
int
insert_names (int sz)
{
	SYM		**hp;
	SYM		*sp;
	NAME		*np;

	/*
	 *	Inicialmente, zera as tabelas.
	 */
	memset (hashtb, 0, sz * sizeof (SYM *));
	memset (symtb,  0, sizeof (symtb));

	/*
	 *	Insere os nomes das funções.
	 */
	for (sp = symtb, np = nametb; np->n_name != NOSTR; np++, sp++)
	{
		strscpy (sp->s_name, np->n_name, sizeof (sp->s_name));

		hp = &hashtb[strhash (sp->s_name, strlen (sp->s_name), sz)];

		if (*hp != NOSYMP)
			return (-1);	/* colisão */

		sp->s_type   = np->n_type;
		sp->s_union  = np->n_id;
	/***	sp->s_hnext  = NOSYMP;	***/
		*hp          = sp;
	}

	return (0);

}	/* end insert_names */
Beispiel #23
0
bool
is_if_link_up(char *ifname)
{
  if (check_wireless_interface(ifname)) {
    /* No link checking on wireless devices */
    return true;
  } else {
    /* Mii wizardry */
    struct ifreq ifr;
    struct mii_data *mii = (struct mii_data *)&ifr.ifr_data;
    int bmsr;
    memset(&ifr, 0, sizeof(ifr));
    strscpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));

    if (ioctl(olsr_cnf->ioctl_s, SIOCGMIIPHY, &ifr) < 0) {
      if (errno != ENODEV)
        OLSR_PRINTF(1, "SIOCGMIIPHY on '%s' failed: %s\n", ifr.ifr_name, strerror(errno));
      return WEIGHT_ETHERNET_DEFAULT;
    }
    mii->reg_num = MII_BMSR;
    if (ioctl(olsr_cnf->ioctl_s, SIOCGMIIREG, &ifr) < 0) {
      OLSR_PRINTF(1, "SIOCGMIIREG on %s failed: %s\n", ifr.ifr_name, strerror(errno));
      return WEIGHT_ETHERNET_DEFAULT;
    }
    bmsr = mii->val_out;

    OLSR_PRINTF(1, "%s: ", ifr.ifr_name);
    OLSR_PRINTF(1, "%s\n", (bmsr & MII_BMSR_LINK_VALID) ? "link ok " : "no link ");

    return (bmsr & MII_BMSR_LINK_VALID);

  }
}
Beispiel #24
0
/**
 *Create a new interf_name struct using a given
 *name and insert it into the interface list.
 *
 *@param name the name of the interface.
 *
 *@return nada
 */
struct olsr_if *
queue_if(const char *name, int hemu)
{
  struct olsr_if *interf_n = olsr_cnf->interfaces;
  size_t name_size;

  //printf("Adding interface %s\n", name);

  /* check if the inerfaces already exists */
  while(interf_n != NULL)
    {
      if(memcmp(interf_n->name, name, strlen(name)) == 0)
	{
	  fprintf(stderr, "Duplicate interfaces defined... not adding %s\n", name);
	  return NULL;
	}
      interf_n = interf_n->next;
    }

  interf_n = olsr_malloc(sizeof(struct olsr_if), "queue interface");

  name_size = strlen(name) + 1;
  interf_n->name = olsr_malloc(name_size, "queue interface name");
  interf_n->cnf = NULL;
  interf_n->interf = NULL;
  interf_n->configured = 0;

  interf_n->host_emul = hemu ? OLSR_TRUE : OLSR_FALSE;

  strscpy(interf_n->name, name, name_size);
  interf_n->next = olsr_cnf->interfaces;
  olsr_cnf->interfaces = interf_n;

  return interf_n;
}
Beispiel #25
0
int
olsr_string_to_prefix(int ipversion, struct olsr_ip_prefix *dst, const char *string) {
  static char buf[MAX(INET6_ADDRSTRLEN + 1 + 3, INET_ADDRSTRLEN + 1 + INET_ADDRSTRLEN)];
  char *ptr;

  strscpy(buf, string, sizeof(buf));
  dst->prefix_len = ipversion == AF_INET ? 32 : 128;

  ptr = strchr(buf, '/');
  if (!ptr) {
    ptr = strchr(buf, ' ');
  }

  if (ptr) {
    *ptr++ = 0;
    if (olsr_cnf->ip_version == AF_INET && strchr(ptr, '.')) {
      uint8_t subnetbuf[4];
      if (inet_pton(AF_INET, ptr, subnetbuf) != 1) {
        return -1;
      }

      dst->prefix_len = netmask_to_prefix(subnetbuf, sizeof(subnetbuf));
    }
    else {
      dst->prefix_len = atoi(ptr);
    }
  }
  return inet_pton(ipversion, buf, &dst->prefix) == 1 ? 0 : -1;
}
Beispiel #26
0
static int	get_net_stat(const char *if_name, net_stat_t *ns)
{
#if defined(HAVE_LIBPERFSTAT)
	perfstat_id_t		ps_id;
	perfstat_netinterface_t	ps_netif;
#endif

	assert(ns);

#if defined(HAVE_LIBPERFSTAT)
	strscpy(ps_id.name, if_name);

	if (-1 == perfstat_netinterface(&ps_id, &ps_netif, sizeof(ps_netif), 1))
		return SYSINFO_RET_FAIL;

	ns->ibytes = (zbx_uint64_t)ps_netif.ibytes;
	ns->ipackets = (zbx_uint64_t)ps_netif.ipackets;
	ns->ierr = (zbx_uint64_t)ps_netif.ierrors;

	ns->obytes = (zbx_uint64_t)ps_netif.obytes;
	ns->opackets = (zbx_uint64_t)ps_netif.opackets;
	ns->oerr = (zbx_uint64_t)ps_netif.oerrors;

	ns->colls = (zbx_uint64_t)ps_netif.collisions;

	return SYSINFO_RET_OK;
#else
	return SYSINFO_RET_FAIL;
#endif
}
Beispiel #27
0
int os_interface_set_state(const char *dev, bool up) {
  int oldflags;
  struct ifreq ifr;

  memset(&ifr, 0, sizeof(ifr));
  strscpy(ifr.ifr_name, dev, IFNAMSIZ);

  if (ioctl(olsr_cnf->ioctl_s, SIOCGIFFLAGS, &ifr) < 0) {
    OLSR_WARN(LOG_INTERFACE, "ioctl SIOCGIFFLAGS (get flags) error on device %s: %s (%d)\n",
        dev, strerror(errno), errno);
    return 1;
  }

  oldflags = ifr.ifr_flags;
  if (up) {
    ifr.ifr_flags |= IFF_UP;
  }
  else {
    ifr.ifr_flags &= ~IFF_UP;
  }

  if (oldflags == ifr.ifr_flags) {
    /* interface is already up/down */
    return 0;
  }

  if (ioctl(olsr_cnf->ioctl_s, SIOCSIFFLAGS, &ifr) < 0) {
    OLSR_WARN(LOG_INTERFACE, "ioctl SIOCSIFFLAGS (set flags %s) error on device %s: %s (%d)\n",
        up ? "up" : "down", dev, strerror(errno), errno);
    return 1;
  }
  return 0;
}
int	VFS_FS_SIZE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
	const MODE_FUNCTION	fl[] =
	{
		{"total",	VFS_FS_TOTAL},
		{"used",	VFS_FS_USED},
		{"pused",	VFS_FS_PUSED},
		{"free",	VFS_FS_FREE},
		{"pfree",	VFS_FS_PFREE},
		{NULL,		0}
	};

	char	fsname[MAX_STRING_LEN], mode[8];
	int	i;

	if (2 < num_param(param))
		return SYSINFO_RET_FAIL;

	if (0 != get_param(param, 1, fsname, sizeof(fsname)))
		return SYSINFO_RET_FAIL;

	if (0 != get_param(param, 2, mode, sizeof(mode)) || '\0' == *mode)
		strscpy(mode, "total");

	for (i = 0; NULL != fl[i].mode; i++)
		if (0 == strcmp(mode, fl[i].mode))
			return (fl[i].function)(fsname, result);

	return SYSINFO_RET_FAIL;
}
Beispiel #29
0
static int	check_ssh(const char *host, unsigned short port, int timeout, int *value_int)
{
	int		ret, major, minor;
	zbx_socket_t	s;
	char		send_buf[MAX_STRING_LEN];
	const char	*buf;

	*value_int = 0;

	if (SUCCEED == (ret = zbx_tcp_connect(&s, CONFIG_SOURCE_IP, host, port, timeout, ZBX_TCP_SEC_UNENCRYPTED, NULL,
			NULL)))
	{
		while (NULL != (buf = zbx_tcp_recv_line(&s)))
		{
			/* parse buf for SSH identification string as per RFC 4253, section 4.2 */
			if (2 == sscanf(buf, "SSH-%d.%d-%*s", &major, &minor))
			{
				zbx_snprintf(send_buf, sizeof(send_buf), "SSH-%d.%d-zabbix_agent\r\n", major, minor);
				*value_int = 1;
				break;
			}
		}

		if (0 == *value_int)
			strscpy(send_buf, "0\n");

		ret = zbx_tcp_send_raw(&s, send_buf);
		zbx_tcp_close(&s);
	}

	if (FAIL == ret)
		zabbix_log(LOG_LEVEL_DEBUG, "SSH check error: %s", zbx_socket_strerror());

	return SYSINFO_RET_OK;
}
Beispiel #30
0
/******************************************************************************
 *                                                                            *
 * Comments: Translate device name to the one used internally by kernel. The  *
 *           translation is done based on minor and major device numbers      *
 *           listed in INFO_FILE_NAME . If the names differ it is usually an  *
 *           LVM device which is listed in kernel device mapper.              *
 *                                                                            *
 ******************************************************************************/
static int	get_kernel_devname(const char *devname, char *kernel_devname, size_t max_kernel_devname_len)
{
	FILE		*f;
	char		tmp[MAX_STRING_LEN], name[MAX_STRING_LEN], dev_path[MAX_STRING_LEN];
	int		ret = FAIL;
	zbx_uint64_t	ds[ZBX_DSTAT_MAX], rdev_major, rdev_minor;
	zbx_stat_t	dev_st;

	if ('\0' == *devname)
		return ret;

	*dev_path = '\0';
	if (0 != strncmp(devname, ZBX_DEV_PFX, ZBX_CONST_STRLEN(ZBX_DEV_PFX)))
		strscpy(dev_path, ZBX_DEV_PFX);
	strscat(dev_path, devname);

	if (zbx_stat(dev_path, &dev_st) < 0 || NULL == (f = fopen(INFO_FILE_NAME, "r")))
		return ret;

	while (NULL != fgets(tmp, sizeof(tmp), f))
	{
		PARSE(tmp);
		if (major(dev_st.st_rdev) != rdev_major || minor(dev_st.st_rdev) != rdev_minor)
			continue;

		zbx_strlcpy(kernel_devname, name, max_kernel_devname_len);
		ret = SUCCEED;
		break;
	}
	zbx_fclose(f);

	return ret;
}