/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*/
#include <alloca.h>
#include <netdb.h>
#include <strings.h>
#include <pthread.h>
#include <sys/systeminfo.h>
#include <unistd.h>
#include "asr.h"
#include "asr_mem.h"
#include "asr_nvl.h"
#include "asr_scf.h"
#include "libasr.h"
static char *asr_reg_props[] = {
};
/*
* Formats local time into a string for debugging messages.
*/
static void
{
else
}
/*
* Sets the property name in the ASR handle with the given value.
*/
int
{
return (EASR_NULLDATA);
}
"Unable to set property %s to %s",
return (ASR_FAILURE);
}
return (ASR_OK);
}
/*
* Sets the property name in the ASR handle with the given value.
* If value isn't set because it is NULL then the default_value will be used.
*/
int
const char *value, const char *default_value)
{
}
/*
* Gets a property from the ASR handle. If the property doesn't exist,
* its value is an empty string or there is an error then the default value is
* returned.
* If there is an error during the operation then asr_errno is set.
*/
char *
{
char *val;
return (NULL);
}
if (err)
val = default_value;
val = default_value;
return (val);
}
/*
* Gets a property from the ASR handle. If the property doesn't exist, its
* value is empty or there was an error then NULL is returned.
*/
char *
{
}
/*
* Gets a boolean property from the ASR handle. If the property doesn't
* exist then the default value is returned.
*/
{
} else {
}
return (retval);
}
/*
* Gets a number property from the ASR handle. If the property doesn't
* exist or can't be parsed then the default value is returned.
*/
long
{
} else {
long lval;
errno = 0;
if (errno == 0)
}
return (retval);
}
/*
* Get the path value for the given property name. The root directory will
* be appended to the path. It is the responsibility of the caller to
* free the resulting string when done.
* If the property isn't set then the default_value will be returned.
* If there is an error then NULL will be returned.
*/
char *asr_getprop_path(
{
int plen;
file = (char *)default_value;
return (NULL);
return (NULL);
else
return (path);
}
/*
* Checks if string contains all the same chars as value c
*/
static boolean_t
{
while (val[0] == c)
val++;
return (val[0] == '\0');
}
/*
* Checks if a string property is set to a valid value. An invalid or unset
* value can be NULL, an empty string, all zeros, all spaces or 'unknown'
*/
static boolean_t
{
return (B_FALSE);
return (B_TRUE);
}
/*
* Checks that a system id is valid and the proper length
*/
static boolean_t
{
}
/*
* Gets the registered asset id of the Solaris host. If one doesn't exist
* a new uuid is generated.
*/
char *
{
if (!asr_is_str_prop_valid(asset_id))
if (!asr_is_str_prop_valid(asset_id)) {
return (NULL);
}
return (asset_id);
}
/*
* Finds system authority information used to populate ASR properties such as
* system-id and product-name from fm libtopo. The FMA authority fields will be
* searched in the following order:
* "system-id" = ("system-serial", "sys-comp-serial", "chassis-serial")
* "product-name" = ("system-name", "sys-comp-name", "chassis-name")
* Stores the FMA authority properties in a cache so that they are available
* for future calls.
*/
static nvlist_t *
{
(void) pthread_mutex_lock(&asr_sysprops_lock);
asr_sysprops = auth;
(void) pthread_mutex_unlock(&asr_sysprops_lock);
return (asr_sysprops);
}
char *
char *name, ...)
{
return (prop);
return (NULL);
return (prop);
}
}
return (NULL);
}
/*
* Gets the system id which should be the 10 digit ASR system identity used
* for asset validation.
* If not found then the system won't be able to be activated with the ASR
* backend service but the generated asset id will be used as the system ID to
* support advanced telemetry. This can happen on older unsupported platforms,
* non Sun hardware and virtual machines.
*/
char *
{
if (asr_issysid_valid(system_id))
return (system_id);
else {
if (asr_topo_set_system_id(ah) == 0)
}
if (asr_issysid_valid(system_id))
return (system_id);
else {
}
}
return (system_id);
else {
}
return (system_id);
}
/*
* Gets the product name of the computer system if available.
*/
char *
{
return (product_name);
else {
if (asr_topo_set_product_name(ah) == 0)
}
}
/*
* Gets the product id of the computer system if available.
*/
char *
{
}
/*
* Gets the site id which is usually the same as the systemid. In the case
* of an appliance the appliance serial number will be used.
*/
char *
{
return (site_id);
}
/*
* Gets the registered ASR client registration id
*/
char *
{
}
/*
* Gets the message signing key length to be used when generating new
*/
{
unsigned long len;
(void) asr_error(EASR_PROP_USAGE,
"Error parsing keylen (%s). Using default value %i",
}
return (len);
}
/*
* Gets the timeout to be used for http requests.
*/
long
{
long nsec;
(void) asr_error(EASR_PROP_USAGE,
"Error parsing http timeout (%s). Using default value %i",
}
nsec *= 1000000L;
return (nsec);
}
/*
* Gets the directory that the phone home service can use for writing
* log files, saving state and temporary data.
*/
char *
{
}
/*
* Gets the registered message signing keys.
*/
char *
{
}
/*
* Gets the current phone-home configuration properties. If the properties
* or handle haven't been initialized then NULL is returned.
*/
nvlist_t *
{
}
/*
* Gets the log file handle used for debugging
*/
FILE *
{
}
/*
* Sets the log file used for debugging
*/
void
{
}
/*
* Sets the configuration name used to save the configuration. The name
* can either be a filename (for debugging) or a service FMRI.
*/
int
{
return (0);
}
}
/*
* Prints the ASR Phone Home configuration properties to the given stream.
* None zero is returned if there is an error.
*/
int
{
return (NULL);
}
}
/*
* Determines if the config is a service FMRI (true) or a file name.
*/
static boolean_t
{
int i;
for (i = 0; svc[i] != '\0'; i++) {
break;
}
}
}
return (is_file);
}
/*
* Saves the ASR configuration properties.
*/
int
{
int err = 0;
err = ASR_FAILURE;
} else if (is_file) {
} else
err = ASR_FAILURE;
} else {
err = ASR_FAILURE;
}
return (err);
}
/*
* Initializes the ASR handle with the given configuration. If there is an
* error then NULL is returned and asr_errno is set.
*/
{
cfg = asr_nvl_alloc();
return (NULL);
}
return (NULL);
}
return (NULL);
}
}
return (ah);
}
/*
* Creates an ASR handle from either a file path name or a service
* FMRI that has ASR properties defined.
* NULL is returned and asr_errno is set if there is an error.
*/
{
return (NULL);
if (is_file) {
return (NULL);
}
} else {
return (NULL);
}
}
}
/*
* Creates an empty registration request structure used for registering a
* client with ASR.
*/
{
}
return (regreq);
}
/*
* Sets the registration transport endpoint which is an optional field.
*/
int
{
(void) asr_set_errno(EASR_NULLDATA);
return (ASR_FAILURE);
}
(void) nvlist_remove_all(
else if (asr_nvl_add_str(
return (ASR_FAILURE);
return (ASR_OK);
}
/*
* Sets the registration user name which is a required field.
*/
int
{
(void) asr_set_errno(EASR_NULLDATA);
return (ASR_FAILURE);
}
return (ASR_FAILURE);
return (ASR_OK);
}
/*
* Sets the registration users credential which is a required field.
*/
int
{
(void) asr_set_errno(EASR_NULLDATA);
return (ASR_FAILURE);
}
password) != 0)
return (ASR_FAILURE);
return (ASR_OK);
}
/*
* Sets the registration proxy host:port with optional credentials
*/
int
{
(void) asr_set_errno(EASR_NULLDATA);
return (ASR_FAILURE);
}
return (ASR_OK);
}
return (ASR_FAILURE);
return (ASR_FAILURE);
return (ASR_FAILURE);
return (ASR_OK);
}
/*
* Gets the transport URL endpoint for an ASR registration request.
*/
char *
{
NULL));
}
/*
* Gets the name of the user requesting an ASR registration.
*/
char *
{
}
/*
* Gets the password of the user requesting an ASR registration.
*/
char *
{
}
int
{
(void) asr_set_errno(EASR_NULLDATA);
return (ASR_FAILURE);
}
return (ASR_OK);
}
/*
* Frees up all resources used for a registration request.
*/
void
{
}
}
{
return;
}
/*
* Initializes the transport functions needed to transmit ASR messages.
*/
int
int (*asr_register_client)(
int (*asr_send_msg)(
{
return (ASR_FAILURE);
return (ASR_OK);
}
/*
* Cleans up the ASR handle when done.
*/
void
{
}
}
} else {
(void) asr_set_errno(EASR_NULLFREE);
}
}
/*
* Cleans up all cached data inside the ASR library.
*/
void
{
(void) pthread_mutex_lock(&asr_sysprops_lock);
if (asr_sysprops != NULL) {
asr_sysprops = NULL;
}
(void) pthread_mutex_unlock(&asr_sysprops_lock);
}
/*
* Cleans up an ASR message and its contents.
*/
void
{
}
}
/*
* Converts a new ASR message from a buffer and the given type.
* Returns NULL and frees data if there is an error.
*/
{
return (NULL);
}
return (msg);
}
/*
* Saves the registration properties into the ASR handle for all future
* message transmission on that handle.
* The name value properties are from a previous call to asr_reg
* Returns non-zero on error.
*/
static int
{
int i, err = 0;
char *r, *val;
else
(void) nvlist_remove_all(cfg, r);
}
return (err);
}
/*
* Fills in the registration response properties taken from the users
* registration request structure and system information.
* Returns ASR_FAILURE if there is an error or ASR_OK if successful.
*/
int
{
return (err);
}
/*
* Registers the ASR client and saves the configuration if successful
* to the ASR handle properties.
* Returns non-zero if there is an error.
*/
int
{
int err = 0;
char *index;
(void) asr_set_errno(EASR_NOMEM);
return (ASR_FAILURE);
}
return (ASR_FAILURE);
else
if (err != 0) {
} else {
"Registered %s", time);
}
}
return (err);
}
/*
* Resets all ASR registration properties
*/
int
{
int i;
char *r;
for (i = 0; (r = asr_reg_props[i]) != NULL; i++) {
(void) nvlist_remove_all(cfg, r);
}
return (ASR_OK);
}
/*
* Deactivates and unregisters ASR for this system.
*/
int
{
int err = 0;
return (0); /* Already unreg'ed */
if (err == 0)
return (err);
}
/*
* Sends the given telemetry data. If the message isn't already signed
* then the signature will be created.
* The output nvlist will have to be freed by the caller even if an error is
* returned since error properties can be returned in out_rsp.
*/
int
{
int err = 0;
return (ASR_FAILURE);
return (err);
}
/*
* Creates an name value list containing ASR common message header properties.
*/
int
{
}
char *
{
return (asr_getprop_strd(
}
{
return (use21);
}
/*
* Creates an name value list containing ASR common message header properties
* and sets the time of the message in the supplied time buffer.
*/
int
{
int err = 0;
return (asr_error(EASR_PROP_NOPROP,
"failed to get system serial number"));
return (asr_error(EASR_PROP_NOPROP,
"failed to get product information"));
"<?xml version='1.0' encoding='UTF-8'?>\n");
"<message xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'\n");
if (use_schema_2_1) {
" xsi:noNamespaceSchemaLocation='message_21.xsd'>\n");
} else {
" xsi:noNamespaceSchemaLocation='message_20.xsd'>\n");
}
if (use_schema_2_1) {
if (freelen > 1) {
if (sysinfo(SI_VERSION,
}
}
}
if (use_schema_2_1) {
}
return (err);
}
int
{
int err = 0;
return (err);
}
/*
* Creates an ASR activation message.
*/
int
{
int err;
return (asr_set_errno(EASR_NOMEM));
pad++;
pad++;
pad--;
pad++;
pad--;
pad++;
pad--;
pad--;
if (err == 0) {
err = EASR_NOMEM;
} else {
}
return (err);
}
/*
* Creates an ASR deactivation message. This message gets sent if registration
* is cleared and ASR should be turned off for the system.
*/
int
{
int err;
return (asr_set_errno(EASR_NOMEM));
if (err == 0) {
err = EASR_NOMEM;
}
} else {
}
return (err);
}
/*
* Creates and ASR heartbeat message.
*/
int
{
int err;
return (asr_set_errno(EASR_NOMEM));
if (err == 0) {
err = EASR_NOMEM;
} else {
}
return (err);
}
/*
* Creates an ASR test message that simulates a fault on the back end and
* sends an email to the given address.
*/
int
{
int err = 0;
return (asr_set_errno(EASR_PROP_USAGE));
return (ASR_FAILURE);
return (ASR_FAILURE);
}
return (asr_set_errno(EASR_NOMEM));
pad++;
pad++;
"Test Message Used for Testing End to End Connection");
pad--;
pad--;
if (err == 0) {
err = EASR_NOMEM;
} else {
}
return (err);
}
/*
* Creates a message that can get the activation status of the devices for
* ASR monitoring validation
*/
int
{
int err;
return (asr_set_errno(EASR_NOMEM));
pad++;
pad++;
pad--;
pad--;
if (err == 0) {
err = EASR_NOMEM;
} else {
}
return (err);
}
/*
* Creates a message that identifies a proactive change to the device state.
* This may have an impact on how Sun views the device.
* This is used for putting a device into maintenance mode and telling Sun that
* a device will go offline (implying it will not send heartbeats for the time
* being).
*/
int
{
int err;
return (asr_set_errno(EASR_NOMEM));
pad++;
pad--;
if (err == 0) {
err = EASR_NOMEM;
} else {
}
return (err);
}
/*
* Internal ASR logging. Logs debug messages, warnings and errors to the
* configured ASR log file.
*/
static void
{
}
/*
* Variable arg version of the internal ASR logger.
*/
/* PRINTFLIKE3 */
static int
{
int err = 0;
return (ASR_FAILURE);
err = -1;
return (err);
}
/*
* Logs the ASR error. If there is no internal error state this function
* does nothing.
*/
void
{
if (asr_get_errno())
}
/*
* Sets the ASR errno and log the error.
*/
void
{
(void) asr_set_errno(err);
}
/*
* Logs the ASR error with the given errno and message.
*/
void
{
}
/*
* Logs a warning to the ASR log.
*/
void
{
}
/*
* Logs an informational message to the ASR log.
*/
void
{
}
/*
* Logs a debug message to the ASR log.
*/
void
{
}
}
/*
* Gets the current ASR debug level.
*/
{
}
/*
* Sets the current ASR debug level.
*/
void
{
(void) asr_setprop_str(
}
}