Ejemplo n.º 1
0
/**
 * Get the *running* O/S identification
 */
static void
swins_get_OS_ident(void)
{
	struct utsname os_id;
	char os_string[SW_NAME_MLEN] = "";
	struct swins_entry *entry;
	u_char *boot;
	struct stat sb;
	struct tm k_ts;

	if (uname(&os_id) == -1) {
		syslog(LOG_WARNING, "%s: %m", __func__);
		return;
	}

	snprintf(os_string, sizeof(os_string), "%s: %s",
	    os_id.sysname, os_id.version);

	if ((entry = swins_find_by_name(os_string)) != NULL ||
	    (entry = swins_entry_create(os_string)) == NULL)
		return;

	entry->flags |= (HR_SWINSTALLED_FOUND | HR_SWINSTALLED_IMMUTABLE);
	entry->id = &oid_zeroDotZero;
	entry->type = (int32_t)SWI_OPERATING_SYSTEM;
	memset(entry->date, 0, sizeof(entry->date));

	if (OS_getSystemInitialLoadParameters(&boot) == SNMP_ERR_NOERROR &&
	    strlen(boot) > 0 && stat(boot, &sb) == 0 &&
	    localtime_r(&sb.st_ctime, &k_ts) != NULL)
		entry->date_len = make_date_time(entry->date, &k_ts, 0);
}
Ejemplo n.º 2
0
/*
 * prototype of this function was genrated by gensnmptree tool in header file
 * hostres_tree.h
 * Returns SNMP_ERR_NOERROR on success
 */
int
op_hrSystem(struct snmp_context *ctx, struct snmp_value *value,
    u_int sub, u_int iidx __unused, enum snmp_op curr_op)
{
	int err;
	u_char *str;

	switch (curr_op) {

          case SNMP_OP_GET:
		switch (value->var.subs[sub - 1]) {

		case LEAF_hrSystemUptime:
			return (OS_getSystemUptime(&value->v.uint32));

		case LEAF_hrSystemDate:
			return (OS_getSystemDate(value));

		case LEAF_hrSystemInitialLoadDevice:
			value->v.uint32 = 0; /* FIXME */
			return (SNMP_ERR_NOERROR);

		case LEAF_hrSystemInitialLoadParameters:
			if ((err = OS_getSystemInitialLoadParameters(&str)) !=
			    SNMP_ERR_NOERROR)
				return (err);
			return (string_get(value, str, -1));

		case LEAF_hrSystemNumUsers:
			return (OS_getSystemNumUsers(&value->v.uint32));

		case LEAF_hrSystemProcesses:
			return (OS_getSystemProcesses(&value->v.uint32));

		case LEAF_hrSystemMaxProcesses:
			return (OS_getSystemMaxProcesses(&value->v.uint32));
		}
		abort();

	  case SNMP_OP_SET:
		switch (value->var.subs[sub - 1]) {

		case LEAF_hrSystemDate:
			if ((ctx->scratch->ptr1 =
			    OS_checkSystemDateInput(value->v.octetstring.octets,
			    value->v.octetstring.len)) == NULL)
				return (SNMP_ERR_WRONG_VALUE);

			return (SNMP_ERR_NOERROR);

		case LEAF_hrSystemInitialLoadDevice:
		case LEAF_hrSystemInitialLoadParameters:
			return (SNMP_ERR_NOT_WRITEABLE);

		}
		abort();

	  case SNMP_OP_ROLLBACK:
		switch (value->var.subs[sub - 1]) {

		case LEAF_hrSystemDate:
			free(ctx->scratch->ptr1);
			return (SNMP_ERR_NOERROR);

		case LEAF_hrSystemInitialLoadDevice:
		case LEAF_hrSystemInitialLoadParameters:
			abort();
		}
		abort();

	  case SNMP_OP_COMMIT:
		switch (value->var.subs[sub - 1]) {

		case LEAF_hrSystemDate:
			(void)OS_setSystemDate(ctx->scratch->ptr1);
			free(ctx->scratch->ptr1);
			return (SNMP_ERR_NOERROR);

		case LEAF_hrSystemInitialLoadDevice:
		case LEAF_hrSystemInitialLoadParameters:
			abort();
		}
		abort();

	  case SNMP_OP_GETNEXT:
		abort();
	}
	abort();
}