Beispiel #1
0
int avtab_write_item(struct policydb *p, struct avtab_node *cur, void *fp)
{
	__le16 buf16[4];
	__le32 buf32[ARRAY_SIZE(cur->datum.u.ops->op.perms)];
	int rc;
	unsigned int i;

	buf16[0] = cpu_to_le16(cur->key.source_type);
	buf16[1] = cpu_to_le16(cur->key.target_type);
	buf16[2] = cpu_to_le16(cur->key.target_class);
	buf16[3] = cpu_to_le16(cur->key.specified);
	rc = put_entry(buf16, sizeof(u16), 4, fp);
	if (rc)
		return rc;

	if (cur->key.specified & AVTAB_OP) {
		rc = put_entry(&cur->datum.u.ops->type, sizeof(u8), 1, fp);
		if (rc)
			return rc;
		for (i = 0; i < ARRAY_SIZE(cur->datum.u.ops->op.perms); i++)
			buf32[i] = cpu_to_le32(cur->datum.u.ops->op.perms[i]);
		rc = put_entry(buf32, sizeof(u32),
				ARRAY_SIZE(cur->datum.u.ops->op.perms), fp);
	} else {
		buf32[0] = cpu_to_le32(cur->datum.u.data);
		rc = put_entry(buf32, sizeof(u32), 1, fp);
	}
	if (rc)
		return rc;
	return 0;
}
Beispiel #2
0
// Test data
void init_entries(void) {
  APP_LOG(APP_LOG_LEVEL_DEBUG, "TEST DATA DO NOT TRUST");
  put_entry("F**k Yea Fire Extinguishers", "Matt F*****g B");
  put_entry("F**k Yea Webscale Data Stores", "Bobert5Evar");
  put_entry("My Hands Are Clean", "DKelle");
  put_entry("S", "Yes, I am a test");
}
Beispiel #3
0
static gboolean incoming_data(GIOChannel *io, GIOCondition cond, gpointer ptr)
{
	int fd = g_io_channel_unix_get_fd(io);
	UNUSED(cond);
	UNUSED(ptr);

	char filename[FILENAME_MAX + 1];
	ssize_t len = recvfrom(fd, filename, FILENAME_MAX, 0, NULL, 0);
	if (len < 0) {
		if (errno == EAGAIN)
			return 0;
		warning("recv failed (%s)\n", strerror(errno));
		g_io_channel_close(io);
		return FALSE;
	}
	if (len == 0) {
		g_io_channel_close(io);
		return FALSE;
	}
	filename[len] = 0;
	struct playlist_entry *entry = add_file_playlist(main_playlist, filename);
	if (entry)
		put_entry(entry);
	return TRUE;
}
Beispiel #4
0
/*
 * Set status of entry/binfmt_misc:
 * '1' enables, '0' disables and '-1' clears entry/binfmt_misc
 */
static int proc_write_status(struct file *file, const char *buffer,
			     unsigned long count, void *data)
{
	struct binfmt_entry *e;
	int res = count;

	if (buffer[count-1] == '\n')
		count--;
	if ((count == 1) && !(buffer[0] & ~('0' | '1'))) {
		if (data) {
			if ((e = get_entry((long) data)))
				e->flags = (e->flags & ~ENTRY_ENABLED)
					    | (int)(buffer[0] - '0');
			put_entry(e);
		} else {
			enabled = buffer[0] - '0';
		}
	} else if ((count == 2) && (buffer[0] == '-') && (buffer[1] == '1')) {
		if (data)
			clear_entry((long) data);
		else
			clear_entries();
	} else {
		res = -EINVAL;
	}
	return res;
}
Beispiel #5
0
int avtab_write_item(struct policydb *p, struct avtab_node *cur, void *fp)
{
	__le16 buf16[4];
	__le32 buf32[1];
	int rc;

	buf16[0] = cpu_to_le16(cur->key.source_type);
	buf16[1] = cpu_to_le16(cur->key.target_type);
	buf16[2] = cpu_to_le16(cur->key.target_class);
	buf16[3] = cpu_to_le16(cur->key.specified);
	rc = put_entry(buf16, sizeof(u16), 4, fp);
	if (rc)
		return rc;
	buf32[0] = cpu_to_le32(cur->datum.data);
	rc = put_entry(buf32, sizeof(u32), 1, fp);
	if (rc)
		return rc;
	return 0;
}
Beispiel #6
0
static void enqueue_one_file(GtkTreeModel *model, GtkTreePath *path,
			     GtkTreeIter *iter, gpointer ptr)
{
	struct playlist_page *page = page_playlist();
	struct playlist_ui_ctx *ctx = get_playlist_ui_ctx(page->playlist);

	UNUSED(model);
	UNUSED(iter);
	UNUSED(ptr);
	struct playlist_entry *entry = entry_from_store(ctx->store, path);
	entry = add_playlist(japlay_queue, get_entry_song(entry), false);
	if (entry)
		put_entry(entry);
}
Beispiel #7
0
static void add_one_file(char *filename, gpointer ptr)
{
	struct playlist_page *page = page_playlist();

	UNUSED(ptr);
	/* first try to load as a playlist */
	if (load_playlist(page->playlist, filename)) {
		struct playlist_entry *entry =
			add_file_playlist(page->playlist, filename);
		if (entry)
			put_entry(entry);
	}
	g_free(filename);
}
Beispiel #8
0
static int write_helper(char *data, size_t len, struct policy_file *file) {
	int idx = 0;
	size_t len2;

	while (len) {
		if (len > BUFSIZ)
			len2 = BUFSIZ;
		else
			len2 = len;
	
		if (put_entry(&data[idx], 1, len2, file) != len2) {
			return -1;
		}
		len -= len2;
		idx += len2;
	}
	return 0;
}
Beispiel #9
0
static void playlist_clicked(GtkTreeView *view, GtkTreePath *path,
	GtkTreeViewColumn *col, gpointer ptr)
{
	struct playlist_page *page = page_playlist();
	if (page->playlist == japlay_queue)
		return;
	struct playlist_ui_ctx *ctx = get_playlist_ui_ctx(page->playlist);

	UNUSED(view);
	UNUSED(col);
	UNUSED(ptr);
	struct playlist_entry *entry = entry_from_store(ctx->store, path);
	entry = add_playlist(japlay_queue, get_entry_song(entry), true);
	if (entry) {
		/* possible race with the playback engine */
		japlay_skip();
		put_entry(entry);
	}
}
Beispiel #10
0
int
bcm_timer_delete(bcm_timer_id timer_id)
{
	ecos_timer_entry_t *entry = (ecos_timer_entry_t *)timer_id;
	ecos_timer_list_t *list = entry->list;
	int status;
	int key;

	TIMERDBG("entry %08x timer %08x", entry, entry->timer);

	/* make sure no interrupts can happen */
	key = INTLOCK();

	/* lock the timer list */
	TIMER_LIST_LOCK(list);

	/* remove the entry from the used list first */
	status = remove_entry(&list->used, entry);
	if (status != 0)
		goto exit0;

	/* delete the backend timer */
	ecos_del_timer(entry);

	/* free the entry back to freed list */
	put_entry(&list->freed, entry);

	entry->flags = TIMER_FLAG_NONE;
	entry->list = NULL;
	TIMER_LIST_UNLOCK(list);

	INTUNLOCK(key);

	TIMERDBG("done");
	return 0;

	/* error handling */
exit0:
	TIMER_LIST_UNLOCK(list);
	INTUNLOCK(key);
	return status;
}
Beispiel #11
0
void in_received_handler(
    DictionaryIterator *received, void *context) {
  // incoming message received
  APP_LOG(APP_LOG_LEVEL_DEBUG, "In Received");
  
  uint32_t size = dict_size(received);
  uint8_t buffer[size];
  
  Tuple *tuple = dict_read_begin_from_buffer(received, buffer, size);
  char buf[500];
  while(tuple) {
    char tmp[500];
    tuple = dict_read_next(received);
    snprintf(tmp, 500, "%s\ntype: %d data:%s", buf, tuple->type, tuple->value->cstring);
    snprintf(buf, 500, "%s", tmp);
  }
  
  tuple = dict_read_first(received);
  
  while (tuple) {
    char name[256];
    char value[256];
    
    for(int i = 0; i < tuple->length; i++) {
      name[i] = tuple->value->cstring[i];
    }
    
    tuple = dict_read_next(received);
    
    if(tuple) {
      for(int i = 0; i < tuple->length; i++) {
        value[i] = tuple->value->cstring[i];
      }
      
      put_entry(name, value);
    } else {
      break;
    }
  }
}
Beispiel #12
0
int avtab_write(struct policydb *p, struct avtab *a, void *fp)
{
	unsigned int i;
	int rc = 0;
	struct avtab_node *cur;
	__le32 buf[1];

	buf[0] = cpu_to_le32(a->nel);
	rc = put_entry(buf, sizeof(u32), 1, fp);
	if (rc)
		return rc;

	for (i = 0; i < a->nslot; i++) {
		for (cur = a->htable[i]; cur; cur = cur->next) {
			rc = avtab_write_item(p, cur, fp);
			if (rc)
				return rc;
		}
	}

	return rc;
}
Beispiel #13
0
/*
* Initialize internal resources used in the timer module. It must be called
* before any other timer function calls. The param 'timer_entries' is used
* to pre-allocate fixed number of timer entries.
*/
int
bcm_timer_module_init(int timer_entries, bcm_timer_module_id *module_id)
{
	int size = timer_entries*sizeof(ecos_timer_entry_t);
	ecos_timer_list_t *list;
	int i;

	TIMERDBG("entries %d", timer_entries);

	/* alloc fixed number of entries upfront */
	list = malloc(sizeof(ecos_timer_list_t)+size);
	if (list == NULL)
		goto exit0;

	cyg_mutex_init(&(list->lock));
	list->flags = TIMER_LIST_FLAG_NONE;
	list->entry = (ecos_timer_entry_t *)(list + 1);
	list->entries = timer_entries;
	TIMERDBG("entry %08x", list->entry);

	/* init the timer entries to form two list - freed and used */
	list->freed = NULL;
	list->used = NULL;
	memset(list->entry, 0, timer_entries*sizeof(ecos_timer_entry_t));

	for (i = 0; i < timer_entries; i ++)
	{
		put_entry(&list->freed, &list->entry[i]);
	}
	list->flags = TIMER_LIST_FLAG_INIT;
	*module_id = (bcm_timer_module_id)list;

	TIMERDBG("list %08x freed %08x used %08x", list, list->freed, list->used);
	return 0;

exit0:
	return -1;
}
Beispiel #14
0
int
bcm_timer_create(bcm_timer_module_id module_id, bcm_timer_id *timer_id)
{
	ecos_timer_list_t *list = (ecos_timer_list_t *)module_id;
	ecos_timer_entry_t *entry;
	int status = -1;

	TIMERDBG("list %08x", list);

	/* lock the timer list */
	TIMER_LIST_LOCK(list);

	/* check if timer is allowed */
	if (list->flags & TIMER_LIST_FLAG_EXIT)
		goto exit0;

	/* alloc an entry first */
	status = get_entry(&list->freed, &entry);
	if (status != 0)
		goto exit0;

	/* add the entry into used list */
	put_entry(&list->used, entry);

	entry->flags = TIMER_FLAG_IN_USE;
	entry->list = list;
	*timer_id = (bcm_timer_id)(void *)entry;

	TIMER_LIST_UNLOCK(list);
	TIMERDBG("entry %08x timer %08x", entry, entry->timer);
	return 0;

	/* error handling */
exit0:
	TIMER_LIST_UNLOCK(list);
	return status;
}
Beispiel #15
0
int sepol_module_package_write(sepol_module_package_t *p, 
			       struct sepol_policy_file *spf)
{
	struct policy_file *file = &spf->pf;
	policy_file_t polfile;
	uint32_t buf[5], offsets[5], len, nsec = 0;
	int i;

	if (p->policy) {
		/* compute policy length */
		polfile.type = PF_LEN;
		polfile.data = NULL;
		polfile.len = 0;
		polfile.handle = file->handle;
		if (policydb_write(&p->policy->p, &polfile))
			return -1;
		len = polfile.len;
		if (!polfile.len)
			return -1;
		nsec++;
		
	} else {
		/* We don't support writing a package without a module at this point */
		return -1;
	}

	/* seusers and user_extra only supported in base at the moment */
	if ((p->seusers || p->user_extra) && (p->policy->p.policy_type != SEPOL_POLICY_BASE)) {
		ERR(file->handle, "seuser and user_extra sections only supported in base");	
		return -1;
	}

	if (p->file_contexts)
		nsec++;

	if (p->seusers)
		nsec++;

	if (p->user_extra)
		nsec++;

	buf[0] = cpu_to_le32(SEPOL_MODULE_PACKAGE_MAGIC);
	buf[1] = cpu_to_le32(p->version);
	buf[2] = cpu_to_le32(nsec);
	if (put_entry(buf, sizeof(uint32_t), 3, file) != 3)
		return -1;

	/* calculate offsets */
	offsets[0] = (nsec + 3) * sizeof(uint32_t);
	buf[0] = cpu_to_le32(offsets[0]);

	i = 1;
	if (p->file_contexts) {
		offsets[i] = offsets[i-1] + len;
		buf[i] = cpu_to_le32(offsets[i]);
		/* add a uint32_t to compensate for the magic number */
		len = p->file_contexts_len + sizeof(uint32_t);
		i++;
	}
	if (p->seusers) {
		offsets[i] = offsets[i-1] + len;
		buf[i] = cpu_to_le32(offsets[i]);
		len = p->seusers_len + sizeof(uint32_t);
		i++;
	}
	if (p->user_extra) {
		offsets[i] = offsets[i-1] + len;
		buf[i] = cpu_to_le32(offsets[i]);
		len = p->user_extra_len + sizeof(uint32_t);
		i++;
	}
	if (put_entry(buf, sizeof(uint32_t), nsec, file) != nsec)
		return -1;

	/* write sections */

	if (policydb_write(&p->policy->p, file))
		return -1;

	if (p->file_contexts) {	
		buf[0] = cpu_to_le32(SEPOL_PACKAGE_SECTION_FC);
		if (put_entry(buf, sizeof(uint32_t), 1, file) != 1)
			return -1;
		if (write_helper(p->file_contexts, p->file_contexts_len, file))
			return -1;
	}
	if (p->seusers) {	
		buf[0] = cpu_to_le32(SEPOL_PACKAGE_SECTION_SEUSER);
		if (put_entry(buf, sizeof(uint32_t), 1, file) != 1)
			return -1;
		if (write_helper(p->seusers, p->seusers_len, file))
			return -1;
		
	}
	if (p->user_extra) {
		buf[0] = cpu_to_le32(SEPOL_PACKAGE_SECTION_USER_EXTRA);
		if (put_entry(buf, sizeof(uint32_t), 1, file) != 1)
			return -1;
		if (write_helper(p->user_extra, p->user_extra_len, file))
			return -1;
	}
	return 0;
}
Beispiel #16
0
/*
 * Get status of entry/binfmt_misc
 * FIXME? should an entry be marked disabled if binfmt_misc is disabled though
 *        entry is enabled?
 */
static int proc_read_status(char *page, char **start, off_t off,
			    int count, int *eof, void *data)
{
	struct binfmt_entry *e;
	char *dp;
	int elen, i, err;

#ifndef VERBOSE_STATUS
	if (data) {
		if (!(e = get_entry((int) data))) {
			err = -ENOENT;
			goto _err;
		}
		i = e->flags & ENTRY_ENABLED;
		put_entry(e);
	} else {
		i = enabled;
	} 
	sprintf(page, "%s\n", (i ? "enabled" : "disabled"));
#else
	if (!data)
		sprintf(page, "%s\n", (enabled ? "enabled" : "disabled"));
	else {
		if (!(e = get_entry((long) data))) {
			err = -ENOENT;
			goto _err;
		}
		sprintf(page, "%s\ninterpreter %s\n",
		        (e->flags & ENTRY_ENABLED ? "enabled" : "disabled"),
			e->interpreter);
		dp = page + strlen(page);
		if (!(e->flags & ENTRY_MAGIC)) {
			sprintf(dp, "extension .%s\n", e->magic);
			dp = page + strlen(page);
		} else {
			sprintf(dp, "offset %i\nmagic ", e->offset);
			dp = page + strlen(page);
			for (i = 0; i < e->size; i++) {
				sprintf(dp, "%02x", 0xff & (int) (e->magic[i]));
				dp += 2;
			}
			if (e->mask) {
				sprintf(dp, "\nmask ");
				dp += 6;
				for (i = 0; i < e->size; i++) {
					sprintf(dp, "%02x", 0xff & (int) (e->mask[i]));
					dp += 2;
				}
			}
			*dp++ = '\n';
			*dp = '\0';
		}
		put_entry(e);
	}
#endif

	elen = strlen(page) - off;
	if (elen < 0)
		elen = 0;
	*eof = (elen <= count) ? 1 : 0;
	*start = page + off;
	err = elen;

_err:
	return err;
}