Example #1
0
SO_PUBLIC struct RazorbackContext *
Razorback_Init_Inspection_Context (uuid_t p_uuidNuggetId,
									 uuid_t p_uuidApplicationType,
									 uint32_t p_iDataTypeCount,
									 uuid_t * p_pDataTypeList,
									 struct RazorbackInspectionHooks *p_pInspectionHooks,
									 uint32_t initialThreads, uint32_t maxThreads) {
	struct RazorbackContext * context = calloc(1, sizeof(struct RazorbackContext));
	uuid_parse("0", context->uuidApplicationType);
	uuid_parse("0", context->uuidNuggetId);
	uuid_parse("0", context->uuidNuggetType);
	context->iFlags = 0;
	context->iDataTypeCount = p_iDataTypeCount;
	context->pDataTypeList = p_pDataTypeList;
	context->pCommandHooks = NULL;
	context->pInspectionHooks = p_pInspectionHooks;
	function = p_pInspectionHooks->processBlock;
	threadInit = p_pInspectionHooks->initThread;
	threadCleanup = p_pInspectionHooks->cleanupThread;
	if (!unshiftContext(context)) {
		free(context);
		rzb_log(LOG_ERR, "%s - failed to store context", __func__);
		return NULL;
	}
	rzb_log(LOG_INFO, "Have inspection function pointer");
	return context;
}
Example #2
0
void* listenerThreadFunc(void* data) {
	char filepath[1000], uuidStr[36], filetype[40], line[1100];
	struct FileDefinition * f;
	uuid_t uuid;
	char c;

	while (true) {
		memset(filepath, '\0', 1000);
		memset(uuidStr, '\0', 36);
		memset(filetype, '\0', 40);
		memset(line, '\0', 1100);


		if (fgets(line, 1100, stdin) != NULL) {
			sscanf(line, "--uuid=%s --type=%s --file=%s\n", uuidStr, filetype, filepath);
			//printf("GOT: line=%s PARSED TO: --uuid=%s --type=%s --file=%s\n", line, uuidStr, filetype, filepath);
		}
		if ( strlen(filepath) > 0 ) {
			if (strcmp(uuidStr, "none") != 0)
				 uuid_parse(uuidStr, uuid);
			else if (strcmp(filetype, "none") != 0)
				 UUID_Get_UUID(filetype, UUID_TYPE_DATA_TYPE, uuid);
			else
				uuid_parse("0", uuid);

			f = createFileDefinition(filepath, uuid);
			Mutex_Lock(mutex);
			pushFileList(f);
			Mutex_Unlock(mutex);
		} else {
			usleep(500000);
		}
	}
	return NULL;
}
Example #3
0
TEST(uuid_test, test_all_uuid_funcs)
{
	char u1str[36+1];
	char u2str[36+1];

	uuid_t u1;
	uuid_t u2;
	uuid_generate(u1);
	uuid_generate_random(u2);
	uuid_unparse(u1, u1str);
	u1str[36] = 0;
	uuid_unparse(u2, u2str);
	u2str[36] = 0;

	fprintf(stderr, "sizeof(uuid): %ld\n", sizeof(u1));
	char zuid[36+1];
	uuid_t tu;
	tu = {0};
	uuid_unparse(tu, zuid);
	fprintf(stderr, "uuid(0): %s\n",zuid) ;
	fprintf(stderr, "uuid_generate(): %s\n", u1str);
	fprintf(stderr, "uuid_generate_random(): %s\n", u2str);

	uuid_t u3;
	uuid_parse(u1str, u3);

	uuid_t u4;
	uuid_parse(u2str, u4);
	// should succeed
	assert(uuid_compare(u1, u3) == 0);
	// should fail
	assert(uuid_compare(u1, u4) == 0);

}
Example #4
0
DC_Workunit *_DC_getWUByName(const char *name)
{
	DC_Workunit *wu;
	char *uuid_str;
	uuid_t uuid;
	int ret;

	if (_DC_wu_table)
	{
		wu = (DC_Workunit *)g_hash_table_lookup(_DC_wu_table, name);
		if (wu)
			return wu;
	}

	/* Check if the WU belongs to this application */
	uuid_str = g_strndup(name, 36);
	ret = uuid_parse(uuid_str, uuid);
	g_free(uuid_str);
	if (ret)
	{
		DC_log(LOG_ERR, "WU name contains illegal UUID");
		return NULL;
	}

	if (uuid_compare(uuid, project_uuid))
	{
		DC_log(LOG_WARNING, "WU does not belong to this application");
		return NULL;
	}

	if (name[36] != '_')
	{
		DC_log(LOG_ERR, "Illegal WU name syntax");
		return NULL;
	}

	/* Check the WU's UUID */
	uuid_str = g_strndup(name + 37, 36);
	ret = uuid_parse(uuid_str, uuid);
	g_free(uuid_str);
	if (ret)
	{
		DC_log(LOG_ERR, "WU name contains illegal UUID");
		return NULL;
	}

	DC_log(LOG_ERR, "WU %s not found!", name);
	return NULL;
}
Example #5
0
int
is_uuid(const char *value)
{
	uuid_t id;
	char test_value[37];

	if (strlen(value) < 36) {
		return 0;
	}

	if (uuid_is_null(id) < 0) {
		errno = EINVAL;
		return -1;
	}

	if (uuid_parse(value, id) < 0) {
		return 0;
	}

	memset(test_value, 0, sizeof(test_value));
	uuid_unparse(id, test_value);

	if (strcasecmp(value, test_value)) {
		return 0;
	}

	return 1;
}
static void
stratcon_datastore_journal(struct sockaddr *remote,
                           const char *remote_cn, char *line) {
  interim_journal_t *ij = NULL;
  char uuid_str[UUID_STR_LEN+1], *cp1, *cp2;
  char rtype[256];
  const char *fqdn = NULL, *dsn = NULL;
  int storagenode_id = 0;
  uuid_t checkid;
  if(!line) {
    mtevL(noit_error, "Error: Line not found for %s in stratcon_datastore_journal\n", remote_cn);
    return;
  }
  cp1 = strchr(line, '\t');
  *rtype = '\0';
  if(cp1 && cp1 - line < sizeof(rtype) - 1) {
    memcpy(rtype, line, cp1 - line);
    rtype[cp1 - line] = '\0';
  }
  /* if it is a UUID based thing, find the storage node */
  switch(*rtype) {
    case 'C':
    case 'S':
    case 'M':
    case 'D':
    case 'B':
    case 'H':
      if((cp1 = strchr(cp1+1, '\t')) != NULL &&
         (cp2 = strchr(cp1+1, '\t')) != NULL &&
         (cp2-cp1 >= UUID_STR_LEN)) {
        strlcpy(uuid_str, cp2 - UUID_STR_LEN, sizeof(uuid_str));
        if(!uuid_parse(uuid_str, checkid)) {
          ingestor->storage_node_lookup(uuid_str, remote_cn, NULL,
                                        &storagenode_id, NULL,
                                        &fqdn, &dsn);
          ij = interim_journal_get(remote, remote_cn, storagenode_id, fqdn);
        }
      }
      break;
    case 'n':
      ij = interim_journal_get(remote,remote_cn,0,NULL);
      break;
    default:
      mtevL(noit_error, "Error: Line has bad type for %s in stratcon_datastore_journal (%s)\n", remote_cn, line);
      break;
  }
  if(!ij) {
    mtevL(ingest_err, "%d\t%s\n", storagenode_id, line);
  }
  else {
    int len;
    len = write(ij->fd, line, strlen(line));
    if(len < 0) {
      mtevL(noit_error, "write to %s failed: %s\n",
            ij->filename, strerror(errno));
    }
  }
  free(line);
  return;
}
Example #7
0
 explicit unique_id_t(const identifier_type& other) {
     if(uuid_parse(other.c_str(), m_uuid) == 0) {
         m_id = other;
     } else {
         throw std::runtime_error("invalid unique id");
     }
 }
Example #8
0
static krb5_error_code KRB5_CALLCONV
xcc_resolve(krb5_context context, krb5_ccache *id, const char *res)
{
    krb5_error_code ret;
    CFUUIDBytes bytes;
    krb5_xcc *x;

    if (uuid_parse(res, (void *)&bytes) != 0) {
	krb5_set_error_message(context, KRB5_CC_END, "failed to parse uuid: %s", res);
	return KRB5_CC_END;
    }
    
    CFUUIDRef uuidref = CFUUIDCreateFromUUIDBytes(NULL, bytes);
    if (uuidref == NULL) {
	krb5_set_error_message(context, KRB5_CC_END, "failed to create uuid from: %s", res);
	return KRB5_CC_END;
    }

    ret = xcc_alloc(context, id);
    if (ret) {
	CFRELEASE_NULL(uuidref);
	return ret;
    }
    
    x = XCACHE((*id));
    
    x->uuid = uuidref;
    genName(x);

    return 0;
}
Example #9
0
File: uuid.c Project: taysom/tau
void get_uuid(char *in, uuid_t out) {
	char t[37];
	memcpy(t, in, 36);
	t[36] = '\0';
	PRs(t);
	uuid_parse(t, out);
}
Example #10
0
//Convert a string to unique id
uuid_t* stringToUniqueID(char* data)
{
	int i;
	uuid_t* uuid = malloc(sizeof(uuid_t));
	uuid_parse(data, uuid);
	return uuid;
}
void test_app_metadata_to_elem_works_without_event_id()
{
	xmlNodePtr new_elem = NULL;
	enum jal_status ret;
	free(app_meta->event_id);
	app_meta->event_id = NULL;
	ret = jalp_app_metadata_to_elem(app_meta, ctx, doc, &new_elem);
	assert_equals(JAL_OK, ret);
	assert_not_equals(NULL, new_elem);

	assert_tag_equals(APP_META_TAG, new_elem);
	xmlDocSetRootElement(doc, new_elem);
	assert_true(0 == validate(doc, __FUNCTION__, TEST_XML_APP_META_TYPES_SCHEMA, 0));

	xmlChar *jid = xmlGetProp(new_elem, xml_jid_attr_name);
	assert_true(0 == strncmp(JID_PREFIX, (char *)jid, strlen(JID_PREFIX)));
	char *uuidstr = (char *)jid + strlen(JID_PREFIX);
	uuid_t uuid;
	assert_true(0 == uuid_parse(uuidstr, uuid));
	xmlFree(jid);

	xmlNodePtr custom = jal_get_first_element_child(new_elem);
	assert_not_equals(NULL, custom);
	assert_tag_equals(CUSTOM_TAG, custom);

	xmlNodePtr should_be_null = custom->next;
	assert_pointer_equals((void*)NULL, should_be_null);
}
Example #12
0
/*ARGSUSED*/
int
cmd_deletekey(TSS_HCONTEXT hContext, TSS_HTPM hTPM, int argc, char *argv[])
{
	TSS_RESULT ret;
	TSS_HOBJECT hKey;
	union {
		uuid_t arr_uuid;
		TSS_UUID tss_uuid;
	} uuid;

	if (argc < 2) {
		(void) fprintf(stderr, gettext("Usage:\n"));
		(void) fprintf(stderr, "\tdeletekey [uuid]\n");
		return (ERR_USAGE);
	}
	if (uuid_parse(argv[1], uuid.arr_uuid))
		return (ERR_FAIL);
	ret = Tspi_Context_UnregisterKey(hContext, TSS_PS_TYPE_USER,
	    uuid.tss_uuid, &hKey);
	if (ret == TSP_ERROR(TSS_E_PS_KEY_NOTFOUND)) {
		ret = Tspi_Context_UnregisterKey(hContext, TSS_PS_TYPE_SYSTEM,
		    uuid.tss_uuid, &hKey);
	}
	if (ret) {
		print_error(ret, gettext("Unregister key"));
		return (ERR_FAIL);
	}
	return (0);
}
int
stratcon_realtime_uri_parse(realtime_context *rc, char *uri) {
  int len, cnt = 0;
  char *cp, *copy, *interest, *brk;
  if(strncmp(uri, "/data/", 6)) return 0;
  cp = uri + 6;
  len = strlen(cp);
  copy = alloca(len + 1);
  if(!copy) return 0;
  memcpy(copy, cp, len);
  copy[len] = '\0';

  for (interest = strtok_r(copy, "/", &brk);
       interest;
       interest = strtok_r(NULL, "/", &brk)) {
    uuid_t in_uuid;
    struct realtime_tracker *node;
    char *interval;

    interval = strchr(interest, '@');
    if(!interval)
      interval = "5000";
    else
      *interval++ = '\0';
    if(uuid_parse(interest, in_uuid)) continue;
    node = calloc(1, sizeof(*node));
    node->rc = rc;
    uuid_copy(node->checkid, in_uuid);
    node->interval = atoi(interval);
    node->next = rc->checklist;
    rc->checklist = node;
    cnt++;
  }
  return cnt;
}
Example #14
0
static int Lisvalid(lua_State *L)		/** isvalid(s) */
{
 uuid_t c;
 const char *s=luaL_checkstring(L,1);
 lua_pushboolean(L,uuid_parse(s,c)==0);
 return 1;
}
Example #15
0
Status genUid(id_t& uid, uuid_string_t& uuid_str) {
  CFDataRef uuid = nullptr;
  if (!genUnlockIdent(uuid).ok()) {
    if (uuid != nullptr) {
      CFRelease(uuid);
    }
    return Status(1, "Could not get unlock ident");
  }

  CFDataGetBytes(uuid, CFRangeMake(0, CFDataGetLength(uuid)), (UInt8*)uuid_str);
  if (uuid != nullptr) {
    CFRelease(uuid);
  }
  
  uuid_t uuidT = {0};
  if (uuid_parse(uuid_str, uuidT) != 0) {
    return Status(1, "Could not parse UUID");
  }

  // id_type >=0 are all valid id types
  int id_type = -1;
  if (mbr_uuid_to_id(uuidT, &uid, &id_type) != 0 && id_type != ID_TYPE_UID) {
    return Status(1, "Could not get uid from uuid");
  }

  return Status(0, "ok");
}
Example #16
0
mtev_reverse_acl_decision_t
reverse_check_allow(const char *id, acceptor_closure_t *ac) {
  mtev_hash_table *config;
  noit_check_t *check;
  const char *key;
  uuid_t uuid;
  char uuid_str[UUID_STR_LEN+1];
  char expected_id[256];

  if(strncmp(id, "check/", 6)) return MTEV_ACL_ABSTAIN;

  strlcpy(uuid_str, id + 6, sizeof(uuid_str));
  if(uuid_parse(uuid_str, uuid) != 0) return MTEV_ACL_DENY;
  uuid_unparse_lower(uuid, uuid_str);

  check = noit_poller_lookup(uuid);
  if(!check) return MTEV_ACL_DENY;

  config = noit_check_get_module_config(check, reverse_check_module_id);
  if(config && mtev_hash_retr_str(config, "secret_key", strlen("secret_key"), &key)) {
    snprintf(expected_id, sizeof(expected_id), "check/%s#%s", uuid_str, key);
  }
  else {
    snprintf(expected_id, sizeof(expected_id), "check/%s", uuid_str);
  }
  if(!strncmp(id, expected_id, strlen(id))) return MTEV_ACL_ALLOW;
  return MTEV_ACL_DENY;
}
void test_app_metadata_to_elem_works_for_logger()
{
	xmlNodePtr new_elem = NULL;
	enum jal_status ret;
	app_meta->type = JALP_METADATA_LOGGER;
	app_meta->log = logger_meta;
	ret = jalp_app_metadata_to_elem(app_meta, ctx, doc, &new_elem);
	assert_equals(JAL_OK, ret);
	assert_not_equals(NULL, new_elem);

	assert_tag_equals(APP_META_TAG, new_elem);
	xmlDocSetRootElement(doc, new_elem);
	assert_equals(0, validate(doc, __FUNCTION__, TEST_XML_APP_META_TYPES_SCHEMA, 0));
	
	xmlChar *jid = xmlGetProp(new_elem, xml_jid_attr_name);
	assert_equals(0, strncmp(JID_PREFIX, (char *)jid, strlen(JID_PREFIX)));
	char *uuidstr = (char *)jid + strlen(JID_PREFIX);
	uuid_t uuid;
	assert_true(0 == uuid_parse(uuidstr, uuid));
	xmlFree(jid);

	xmlNodePtr event_id = jal_get_first_element_child(new_elem);
	assert_not_equals(NULL, event_id);
	assert_tag_equals(EVENT_ID_TAG, event_id);
	assert_content_equals(EVENT_ID, event_id);

	xmlNodePtr logger = event_id->next;
	assert_not_equals(NULL, logger);
	assert_tag_equals(LOGGER_TAG, logger);

	xmlNodePtr should_be_null = logger->next;
	assert_pointer_equals((void*)NULL, should_be_null);

	app_meta->sys = NULL;
}
Example #18
0
CID CID::FromString(const std::string &cid) {
  uuid_t uuid;
  int ret = uuid_parse(cid.data(), uuid);
  if (ret == -1)
    uuid_clear(uuid);
  return CID(uuid);
}
Example #19
0
static int Ltime(lua_State *L)			/** time(s) */
{
 uuid_t c;
 const char *s=luaL_checkstring(L,1);
 if (uuid_parse(s,c)!=0) return 0;
 lua_pushnumber(L,uuid_time(c,NULL));
 return 1;
}
Example #20
0
static int Lparse(lua_State *L)		   /** parse(uuidstring) */
{
 uuid_t c;
 const char *s=luaL_checkstring(L,1);
 if (uuid_parse(s,c))
   return 0;
 lua_pushlstring(L,(const char*)c,sizeof(c));
 return 1;
}
void setup()
{
	memset(&rec, 0, sizeof(rec));
	memset(&app_meta, 0, sizeof(app_meta));
	memset(&payload, 0, sizeof(payload));
	rec.pid = 1234;
	rec.uid = 5678;
	rec.source = SOURCE;
	rec.hostname = HOSTNAME;
	rec.timestamp = TIMESTAMP;
	rec.username = USERNAME;
	rec.sec_lbl = SEC_LABEL;
	rec.have_uid = 1;
	rec.version = 1;
	rec.payload = jaldb_create_segment();
	assert_equals(0, uuid_parse(REC_UUID, rec.uuid));
	assert_equals(0, uuid_parse(HOST_UUID, rec.host_uuid));
}
Example #22
0
gboolean
nk_uuid_parse(NkUuid *self, const gchar *string)
{
    if ( uuid_parse(string, self->data) < 0 )
        return FALSE;

    nk_uuid_update_string(self);
    return TRUE;
}
Example #23
0
BOOL UUID_FromString(PSTR szUUID,GUID *uuid)
{
#ifdef WIN32
  return RPC_S_OK == UuidFromString(szUUID,uuid);
#endif //WIN32
#ifdef HAVE_UUID_PARSE
  return uuid_parse(szUUID,uuid);
#endif //HAVE_UUID_PARSE
}
Example #24
0
File: dom.c Project: UIKit0/calfbox
gboolean cbox_uuid_fromstring(struct cbox_uuid *uuid, const char *str, GError **error)
{
    if (uuid_parse(str, uuid->uuid))
    {
        g_set_error(error, CBOX_MODULE_ERROR, CBOX_MODULE_ERROR_FAILED, "Malformed UUID: '%s'", str);
        return FALSE;
    }
    return TRUE;
}
Example #25
0
gboolean
is_uuid_valid (const char *uuid_str)
{
    uuid_t uuid;

    if (uuid_parse (uuid_str, uuid) < 0)
        return FALSE;
    return TRUE;
}
Example #26
0
int DC_initMaster(const char *config_file)
{
	char *cfgval;
	int ret;

	_DC_init_common();

	if (!config_file)
		config_file = DC_CONFIG_FILE;

	ret = _DC_parseCfg(config_file);
	if (ret)
	{
		DC_log(LOG_ERR, "The DC-API cannot be initialized without a "
			"config file");
		return ret;
	}

	/* Check the working directory */
	cfgval = DC_getCfgStr(CFG_WORKDIR);
	if (!cfgval)
	{
		DC_log(LOG_ERR, "%s is not specified in the config file",
			CFG_WORKDIR);
		return DC_ERR_CONFIG;
	}
	free(cfgval);

	/* Check sleep interval */
	sleep_interval = DC_getCfgInt(CFG_SLEEPINTERVAL, DEFAULT_SLEEP_INTERVAL);
	if (sleep_interval < 1)
		sleep_interval = 1;

	/* Check the project UUID */
	cfgval = DC_getCfgStr(CFG_INSTANCEUUID);
	if (!cfgval)
	{
		DC_log(LOG_ERR, "%s is not set in the config file",
			CFG_INSTANCEUUID);
		return DC_ERR_CONFIG;
	}

	ret = uuid_parse((char *)cfgval, project_uuid);
	if (ret)
	{
		DC_log(LOG_ERR, "Invalid project UUID");
		free(cfgval);
		return DC_ERR_CONFIG;
	}
	free(cfgval);

	/* Enforce a canonical string representation of the UUID */
	uuid_unparse_lower(project_uuid, project_uuid_str);

	return DC_OK;
}
Example #27
0
/* Change the swap partition info */
static int change_info(const char *devname, const char *label, const char *uuid)
{
	int fd;

	fd = open(devname, O_RDWR);
	if (fd < 0) {
		warn(_("%s: failed to open"), devname);
		goto err;
	}
#ifdef HAVE_LIBUUID
	/* Write the uuid if it was provided */
	if (uuid) {
		uuid_t newuuid;

		if (uuid_parse(uuid, newuuid) == -1)
			warnx(_("failed to parse UUID: %s"), uuid);
		else {
			if (lseek(fd, SWAP_UUID_OFFSET, SEEK_SET) !=
							SWAP_UUID_OFFSET) {
				warn(_("%s: failed to seek to swap UUID"), devname);
				goto err;

			} else if (write_all(fd, newuuid, sizeof(newuuid))) {
				warn(_("%s: failed to write UUID"), devname);
				goto err;
			}
		}
	}
#endif
	/* Write the label if it was provided */
	if (label) {
		char newlabel[SWAP_LABEL_LENGTH];

		if (lseek(fd, SWAP_LABEL_OFFSET, SEEK_SET) != SWAP_LABEL_OFFSET) {
			warn(_("%s: failed to seek to swap label "), devname);
			goto err;
		}
		memset(newlabel, 0, sizeof(newlabel));
		xstrncpy(newlabel, label, sizeof(newlabel));

		if (strlen(label) > strlen(newlabel))
			warnx(_("label is too long. Truncating it to '%s'"),
					newlabel);
		if (write_all(fd, newlabel, sizeof(newlabel))) {
			warn(_("%s: failed to write label"), devname);
			goto err;
		}
	}

	close(fd);
	return 0;
err:
	if (fd >= 0)
		close(fd);
	return -1;
}
bool plUUID::FromString( const char * str )
{
    Clear();
    if ( !str )
        return false;
    uuid_t g;
    uuid_parse( str, g );
    plUUIDHelper::CopyToPlasma( this, g );
    return true;
}
Example #29
0
adapter::Guid
adapter::Guid::Parse(char const* s)
{
  if (s == NULL)
    return Guid::Null();

  uuid_t id;
  return (uuid_parse(s, id) == 0)
    ? Guid(id)
    : Guid::Null();
}
Example #30
0
	bool UUID::initializeFromCString(const char* cstring)
	{
		# ifndef YUNI_OS_WINDOWS
		// Why uuid_parse takes a char* and not a const char* ??
		return !uuid_parse(const_cast<char*>(cstring), pValue.cstring);
		# else
		// Stop complaining, the Windows implementation is way worse.
		char* cstring_noconst = const_cast<char*>(cstring);
		unsigned char* cstring_unsigned = (unsigned char*)(cstring_noconst);
		return RPC_S_OK == ::UuidFromStringA(cstring_unsigned, (::GUID*)pValue.cstring);
		# endif
	}