Exemple #1
0
/*
* Service Control Handler. This is called when the SCM sends the "Stop" signal
*/
void ServiceCtrlHandler(DWORD ctrl)
{
	BOOL stop_service = FALSE;
	TCHAR szMsg[COMMON_VALUE_LEN];

	s_snprintf(szMsg, COMMON_VALUE_LEN, "%s service stopping.", g_serviceName);
	switch (ctrl)
	{
		case SERVICE_CONTROL_STOP:
			log_system_event(SYSTEM_EVENT_TYPE_INFO, szMsg,
					"Received SERVICE_CONTROL_STOP.");
			stop_service = TRUE;
			break;
		case SERVICE_CONTROL_SHUTDOWN:
			log_system_event(SYSTEM_EVENT_TYPE_INFO, szMsg,
					"Received SERVICE_CONTROL_SHUTDOWN.");
			stop_service = TRUE;
			break;
		case SERVICE_CONTROL_INTERROGATE:
			break;
		default:
			break;
	}

	if (stop_service == TRUE)
	{

		setServiceStatus(SERVICE_STOP_PENDING, true, NO_ERROR, 0);

		// signal threads to stop
		SetEvent(g_serviceStopEvent);
	}
}
Exemple #2
0
// ----------------------------------------------------------------------------
// the callback used to format data (into text, json, html, etc.) for clients
// ----------------------------------------------------------------------------
// HTTP/1.1 200 OK
// Content-type:text/plain
// Transfer-Encoding: chunked
// 
// 3c;     
// KEY:time VAL:Mon, 12 Mar 2012 13:11:49 GMT|KEY:00 VAL:14.03
// 3c;     
// KEY:time VAL:Mon, 12 Mar 2012 13:11:49 GMT|KEY:00 VAL:40.75
// 3c;     
// KEY:time VAL:Mon, 12 Mar 2012 13:11:49 GMT|KEY:00 VAL:45.02
// 0   
//
static int push_fn(char *argv[], xbuf_t *reply)
{
   reply->len = 0; // empty buffer
   xbuf_xcat(reply, "        \r\n" // room for chunck size: "1a;     "
             "KEY:time VAL:%s|", (char*)get_env(argv, SERVER_DATE));
             
   // fill the 2D HTML <table> cells with our 1D array
   // (we randomly skip some cells to avoid updating all of them)
   {
      int i = 0, r = 0, c = 0;
      while(i < CELLS)
      {
          if(!(sw_rand(&rnd) & 3)) // skip some cells
             xbuf_xcat(reply, "KEY:%c%c VAL:%.02f|",
                              '0' + r, '0' + c, s_data[i++]);

          if(c + 1 < COLS) c++; 
          else
          {
             c = 0;
             if(r + 1 < ROWS) r++; else r = 0;
          }
      }
   }   
   reply->ptr[--reply->len] = 0; // remove the ending '|'
   
   // now we know it, setup the chunk size
   char *p = reply->ptr;
   int i = s_snprintf(p, 8, "%x;", reply->len - (sizeof("        \r\n") - 2));
   p[i] = ' '; // useful for tracing, when we puts(reply->ptr); later
   
   xbuf_ncat(reply, "\r\n", sizeof("\r\n") - 1); // close this chunk
   return 1;   
}
std::string wbem::support::DiagnosticLogFactory::buildDiagnosticResultMessage(
		struct event *p_event)
{
	std::string msg_str;
	char msg[NVM_EVENT_MSG_LEN];
	s_snprintf(msg, (NVM_EVENT_MSG_LEN + (3 * NVM_EVENT_ARG_LEN)),
			p_event->message, p_event->args[0], p_event->args[1], p_event->args[2]);
	msg_str = msg;
	return msg_str;
}
/*
 * Constructor
 */
wbem::exception::NvmExceptionNotManageable::NvmExceptionNotManageable(const char *pUnmanageableDimm)
: wbem::framework::Exception()
{
	m_unmanageableDimm = pUnmanageableDimm != NULL ? pUnmanageableDimm : "";
	char description[ERROR_MESSAGE_LEN];

 	s_snprintf(description, ERROR_MESSAGE_LEN, EXCEPTION_NOTMANAGEABLE_MSG.c_str(),
 			pUnmanageableDimm);
	m_Message = description;
	logDebugMessage();
}
Exemple #5
0
/*
** Get the OS name and version number
*/
char *
osinfo_get(char *buf,
	   int bufsize)
{
#ifdef HAVE_UNAME
    struct utsname ub;

    if (uname(&ub) < 0)
	return NULL;
    
#ifndef _AIX
    s_snprintf(buf, bufsize, "%s %s", ub.sysname, ub.release);
#else
    s_snprintf(buf, bufsize, "%s %s.%s", ub.sysname, ub.version, ub.release);
#endif
#else
    if (strlcpy(buf, "<unknown>", bufsize) >= bufsize)
	return NULL;
#endif

    return buf;
}
Exemple #6
0
// ----------------------------------------------------------------------------
int main(int argc, char *argv[])
{
   xbuf_t *reply = get_reply(argv);

   // encode string
   char buf[80], user[80] = "*****@*****.**";
   int ret = s_snprintf(buf, 255, "%B", user);
   xbuf_xcat(reply, "<p>plain text %s to base64:<br> &nbsp; %s (len: %d)</p>",
             user, buf, ret);

   // decode string
   ret = s_snprintf(user, 255, "%-B", buf);
   xbuf_xcat(reply, "<p>base64 %s to plain text:<br> &nbsp; %s (len: %d)</p>",
             buf, user, ret);

   // encode binary data
   memset(user, 0, 8);
   ret = s_snprintf(buf, 255, "%8B", user);
   xbuf_xcat(reply, "<p>8 null bytes to base64:<br> &nbsp; %s (len: %d)</p>",
             buf, ret);

   // decode binary data
   memset(user, 'A', 16);
   ret = s_snprintf(user, 255, "%-B", buf);
   xbuf_xcat(reply, "<p>base64 %s to binary:<br> &nbsp; %s (len: %d)</p>",
             buf, 
             memcmp(user, "\0\0\0\0\0\0\0", 8) ? "mismatch" : "OK, match", 
             ret);

   // dump binary data            
   int i = 0;          
   while(i < 16)
      xbuf_xcat(reply, "user[%d] = %d<br>", i, user[i]), i++;

   return 200; // return an HTTP code (200:'OK')
}
Exemple #7
0
char *
strerror(int err)
{
#ifdef NEED_SYS_ERRLIST
    extern int sys_nerr;
    extern char *sys_errlist[];
#endif
    static char errbuf[64];

    if (err < 0 || err >= sys_nerr)
    {
	if (s_snprintf(errbuf, sizeof(errbuf), "#%d", err) < 0)
	    return "<unknown>";
	
	return errbuf;
    }
    else
	return sys_errlist[err];
}
/*
 * Run the security check diagnostic algorithm
 */
int diag_security_check(const struct diagnostic *p_diagnostic, NVM_UINT32 *p_results)
{
	COMMON_LOG_ENTRY();
	int rc = NVM_SUCCESS;
	int dev_count = 0;
	*p_results = 0;

	// clear previous results
	diag_clear_results(EVENT_TYPE_DIAG_SECURITY, 0, NULL);

	if ((rc = IS_NVM_FEATURE_SUPPORTED(security_diagnostic)) != NVM_SUCCESS)
	{
		COMMON_LOG_ERROR("The security diagnostic is not supported.");
	}
	else
	{
		dev_count = nvm_get_device_count();
		if (dev_count == 0)
		{
			store_event_by_parts(EVENT_TYPE_DIAG_SECURITY, EVENT_SEVERITY_WARN,
					EVENT_CODE_DIAG_SECURITY_NO_DIMMS, NULL, 0, NULL, NULL, NULL,
					DIAGNOSTIC_RESULT_ABORTED);
			(*p_results)++;
		}
		else if (dev_count > 0)
		{
			// get device_discovery information of all dimms
			struct device_discovery dimms[dev_count];
			int manageable_dev_count = 0;
			dev_count = nvm_get_devices(dimms, dev_count);
			if (dev_count > 0)
			{
				rc = NVM_SUCCESS;
				// count the number of dimms in each security state.
				int security_state_count = (int)LOCK_STATE_NOT_SUPPORTED;

				int count[security_state_count+1];
				memset(count, 0, sizeof (int) * (security_state_count + 1));
				for (int i = 0; i < dev_count; i++)
				{
					// only take dimms that are manageable into account
					if (dimms[i].manageability == MANAGEMENT_VALIDCONFIG)
						{
							count[dimms[i].lock_state]++;
							manageable_dev_count++;
						}
				}

				// check if all manageable dimms are security not supported
				if ((count[LOCK_STATE_NOT_SUPPORTED] == manageable_dev_count) &&
						(!(p_diagnostic->excludes &
								DIAG_THRESHOLD_SECURITY_ALL_NOTSUPPORTED)))
				{
					store_event_by_parts(EVENT_TYPE_DIAG_SECURITY,
							EVENT_SEVERITY_WARN,
							EVENT_CODE_DIAG_SECURITY_ALL_NOTSUPPORTED, NULL, 0, NULL,
							NULL, NULL, DIAGNOSTIC_RESULT_FAILED);
					(*p_results)++;
				}
				// check if all manageable dimms are disabled
				else if ((count[LOCK_STATE_DISABLED] == manageable_dev_count) &&
					(!(p_diagnostic->excludes & DIAG_THRESHOLD_SECURITY_ALL_DISABLED)))
				{
					store_event_by_parts(EVENT_TYPE_DIAG_SECURITY,
							EVENT_SEVERITY_WARN,
							EVENT_CODE_DIAG_SECURITY_ALL_DISABLED, NULL, 0, NULL,
							NULL, NULL, DIAGNOSTIC_RESULT_FAILED);
					(*p_results)++;
				}

				if (*p_results == 0)
				{
					// check if all manageable dimms have the same security state
					if (!(p_diagnostic->excludes & DIAG_THRESHOLD_SECURITY_CONSISTENT))
					{
						char inconsistent_security_state_event_arg_str[NVM_EVENT_ARG_LEN];
						NVM_BOOL inconsistent_flag = 0;
						for (int j = 0; j < security_state_count; j++)
						{
							// check if security settings are inconsistent
							if (count[j] > 0 && count[j] != manageable_dev_count)
							{
								// appending to the argument
								if (inconsistent_flag)
								{
									s_strcat(inconsistent_security_state_event_arg_str,
											NVM_EVENT_ARG_LEN, ", ");
								}
								char arg_str_security_state[NVM_EVENT_ARG_LEN];
								s_snprintf(arg_str_security_state, NVM_EVENT_ARG_LEN,
										"%d %s", count[j], lock_state_strings[j]);
								s_strcat(inconsistent_security_state_event_arg_str,
										NVM_EVENT_ARG_LEN, arg_str_security_state);
								inconsistent_flag = 1;
							}
						}

						if (inconsistent_flag)
						{
							store_event_by_parts(EVENT_TYPE_DIAG_SECURITY,
									EVENT_SEVERITY_WARN,
									EVENT_CODE_DIAG_SECURITY_INCONSISTENT, NULL, 0,
									inconsistent_security_state_event_arg_str, NULL,
									NULL, DIAGNOSTIC_RESULT_FAILED);
							(*p_results)++;
						}
					}
				}

			} // nvm_get_devices failed
			else
			{
				rc = dev_count;
			}
		} // nvm_get_device_count failed
		else
		{
			rc = dev_count;
		}

		// add success message
		if ((rc == NVM_SUCCESS) && (*p_results == 0)) // No errors/warnings
		{
			// store success event
			store_event_by_parts(
				EVENT_TYPE_DIAG_SECURITY,
				EVENT_SEVERITY_INFO,
				EVENT_CODE_DIAG_SECURITY_SUCCESS,
				NULL,
				0,
				NULL,
				NULL,
				NULL,
				DIAGNOSTIC_RESULT_OK);
			(*p_results)++;
		}

	}

	COMMON_LOG_EXIT_RETURN_I(rc);
	return rc;
}