Exemple #1
0
void request_clear(request_t* request)
{
        list_t* n;

        if (request->path) 
                free(request->path);

        n = request->pathnodes;
        while (n) {
                free(n->data);
                n = n->next;
        }
        delete_list(request->pathnodes);

        n = request->args;
        while (n) {
                delete_pair((pair_t*)n->data);
                n = n->next;
        }
        delete_list(request->args);

        n = request->headers;
        while (n) {
                delete_pair((pair_t*)n->data);
                n = n->next;
        }
        delete_list(request->headers);

        if (request->body) 
                free(request->body);

        memset(request, 0, sizeof(request_t));
}
static void change_identity_elevate_for_sups(norm_pcred_pair_t const* np) {
    // Elevate privileges to change sups, then transition to target identity

    // Get the uids of the intermediate privileged state we will use for
    // setting sups
    uids_t const priv_norm_uids = get_suid_for_identity_change(np);

    // HACK: Recycle code for denormalizing parameter lists to denormalize
    // the real, effective, and saved uids for our intermediate privileged
    // state
    uid_t const normalized_priv_uids[3] = {
        priv_norm_uids.r,
        priv_norm_uids.e,
        priv_norm_uids.s
    };
    uid_t actual_priv_uids[3];
    map_uids_params(
        &np->uids_map,
        3,
        normalized_priv_uids,
        actual_priv_uids);

    // Construct pair for first jump: current state -> privileged state
    pcred_pair_t p1 = get_pair_current(false);
    p1.next.uids.r = actual_priv_uids[0];
    p1.next.uids.e = actual_priv_uids[1];
    p1.next.uids.s = actual_priv_uids[2];
    norm_pcred_pair_t const np1 = get_normalized_pcred_pair(&p1);

    // Change effective user to privileged value
    assert(set_uids_from_graph(&np1) == 0);
    delete_pair(&p1);

    // Construct pair for second jump:
    // new current (privileged) state -> target state
    pcred_pair_t p2 = get_pair_current(false);
    p2.next.uids = np->next.actual.uids;
    p2.next.gids = np->next.actual.gids;
    p2.next.sups = np->next.sups;
    norm_pcred_pair_t const np2 = get_normalized_pcred_pair(&p2);

    assert(
        set_sups(&np2.next.sups) == 0 &&  // Change sups to target value
        set_gids_from_graph(&np2) == 0 && // Change groups to target value
        set_uids_from_graph(&np2) == 0);  // Change user to target value
    delete_pair(&p2);
}
Exemple #3
0
int qse_rbt_delete (rbt_t* rbt, const void* kptr, size_t klen)
{
	pair_t* pair;

	pair = qse_rbt_search (rbt, kptr, klen);
	if (pair == QSE_NULL) return -1;

	delete_pair (rbt, pair);
	return 0;
}
Exemple #4
0
void fa_pair_deep_destroy(fa_pair_t pair, fa_deep_destroy_pred_t pred)
{
    if (!pred(pair)) return;
    fa_ptr_t a = pair->values[0];
    fa_ptr_t b = pair->values[1];
    //fa_log_info(fa_dappend(fa_string("  destroying pair 1 "), fa_string_show(pair)));
    if (a) fa_deep_destroy(a, pred);
    //fa_log_info(fa_string("  destroying pair 2"));
    if (b) fa_deep_destroy(b, pred);
    //fa_log_info(fa_string("  destroying pair 3"));
    delete_pair(pair);
}
Exemple #5
0
void fa_pair_destroy(fa_pair_t pair)
{
    delete_pair(pair);
}
Exemple #6
0
int parse_baf(GapIO *io, char *fn, tg_args *a) {
    int nseqs = 0, nobj = 0, ntags = 0, ncontigs = 0;
    struct stat sb;
    zfp *fp;
    off_t pos;
    contig_t *c = NULL;
    tg_pair_t *pair = NULL;
    baf_block *b, *co = NULL;
    int last_obj_type = 0;
    int last_obj_pos = 0;
    tg_rec last_obj_rec = 0;
    tg_rec last_cnt_rec = 0;
    int last_cnt_pos = 0;
    int last_obj_orient = 0;
    
    
	
    printf("Loading %s...\n", fn);
    if (-1 == stat(fn, &sb) ||
	NULL == (fp = zfopen(fn, "r"))) {
	perror(fn);
	return -1;
    }

    if (a->pair_reads) {
	pair = create_pair(a->pair_queue);
    }

    /* Loop:
     * Read 1 block of data.
     * If contig, create contig
     * If read, insert it, insert to index.
     * Anything else - reject for now
     */
    pos = 0;
    while (b = baf_next_block(fp)) {
	int delay_destroy = 0;

	switch (b->type) {
	case CO: {
	    char *contig = baf_block_value(b, CO);

	    if (co)
		baf_block_destroy(co);

	    co = b;
	    delay_destroy = 1;

	    ncontigs++;
	    
	    create_new_contig(io, &c, contig, a->merge_contigs);

	    /* For anno */
	    last_obj_type = GT_Contig;
	    last_obj_rec = c->rec;
	    last_obj_pos = c->start + 1;
	    last_cnt_rec = c->rec;
	    last_cnt_pos = c->start + 1;
	    last_obj_orient = 0;

	    break;
	}

	case RD: {
	    seq_t seq;
	    int flags;
	    char *tname;
	    tg_rec recno;
	    int is_pair = 0;

	    /* Construct seq struct */
	    if (-1 == construct_seq_from_block(a, &seq, b, &tname)) {
		fprintf(stderr, "Failed to parse read block for seq %d\n",
			nseqs);
		break;
	    }

	    /* Create range, save sequence */
	    flags = GRANGE_FLAG_TYPE_SINGLE;
	    
	    if (seq.flags & SEQ_END_REV)
		flags |= GRANGE_FLAG_END_REV;
	    else
		flags |= GRANGE_FLAG_END_FWD;
	    if (seq.len < 0)
		flags |= GRANGE_FLAG_COMP1;
		
	    if (pair) is_pair = 1;
		
	    recno = save_range_sequence(io, &seq, seq.mapping_qual, pair,
					is_pair, tname, c, a, flags, NULL);

	    /* For anno */
	    last_obj_type = GT_Seq;
	    last_obj_rec = recno;
	    if (seq.len >= 0) {
		last_obj_pos = seq.pos;
		last_obj_orient = 0;
	    } else {
		last_obj_pos = seq.pos - seq.len - 1;
		last_obj_orient = 1;
	    }

	    nseqs++;
	    
	    break;
	}

	case AN: {
	    range_t r;
	    anno_ele_t *e;
	    char *typ = baf_block_value(b, AN);
	    char *loc = baf_block_value(b, LO);
	    char *len = baf_block_value(b, LL);
	    char *txt = baf_block_value(b, TX);
	    char *at  = baf_block_value(b, AT);
	    int an_pos;
	    bin_index_t *bin;
	    int anno_obj_type;

	    if (!(a->data_type & DATA_ANNO))
		break;

	    if (txt)
		unescape_line(txt);

	    if (last_obj_type == GT_Contig || (at && *at == 'C'))
		anno_obj_type = GT_Contig;
	    else
		anno_obj_type = GT_Seq;

	    if (!loc) {
		an_pos = last_obj_pos;
	    } else {
		if (*loc == '@') {
		    an_pos = atoi(loc+1);
		} else {
		    if (anno_obj_type == GT_Contig) {
			if (last_obj_orient == 0)
			    an_pos = last_cnt_pos + atoi(loc)-1;
			else
			    an_pos = last_cnt_pos - (atoi(loc)-1)
				- (len ? atoi(len)-1 : 0);
		    } else {
			if (last_obj_orient == 0)
			    an_pos = last_obj_pos + atoi(loc)-1;
			else
			    an_pos = last_obj_pos - (atoi(loc)-1)
				- (len ? atoi(len)-1 : 0);
		    }
		}
	    }

	    r.start = an_pos;
	    r.end = an_pos + (len ? atoi(len)-1 : 0);

	    r.mqual = str2type(typ);
	    r.pair_rec = (anno_obj_type == GT_Contig)
		? last_cnt_rec
		: last_obj_rec;

	    r.flags = GRANGE_FLAG_ISANNO;
	    if (GT_Seq == anno_obj_type)
		r.flags |= GRANGE_FLAG_TAG_SEQ;
	    r.rec = anno_ele_new(io, 0, anno_obj_type, r.pair_rec, 0,
				 str2type(typ), txt);
	    e = (anno_ele_t *)cache_search(io, GT_AnnoEle, r.rec);
	    e = cache_rw(io, e);
	
	    bin = bin_add_range(io, &c, &r, NULL, NULL, 0);
	    e->bin = bin->rec;

	    ntags++;
	    break;
	}

	case 0:
	    /* blank line */
	    break;

	default:
	    printf("Unsupported block type '%s'\n",
		   linetype2str(b->type));
	}

	if (!delay_destroy)
	    baf_block_destroy(b);

	if ((++nobj & 0xfff) == 0) {
	    int perc = 0;

	    pos = zftello(fp);
	    perc = 100.0 * pos / sb.st_size;
	    printf("\r%d%c", perc, (nobj & 0x3fff) ? '%' : '*');
	    fflush(stdout);
	    if ((nobj & 0x3fff) == 0)
		cache_flush(io);
	}

#if 1
	if ((nobj & 0x3fff) == 0) {
	    static int perc = 0;
	    if (perc < 100.0 * pos / sb.st_size) {
		perc = 100.0 * pos / sb.st_size;
		printf("\r%d%%", perc);
		//HacheTableStats(io->cache, stdout);
		//HacheTableStats(((GDB **)io->dbh)[0]->gfile->idx_hash, stdout);
		{
		    static struct timeval last, curr;
		    static int first = 1;
		    static int last_obj = 0;
		    static int last_contigs = 0;
		    long delta;

		    gettimeofday(&curr, NULL);
		    if (first) {
			last = curr;
			first = 0;
		    }

		    delta = (curr.tv_sec - last.tv_sec) * 1000000
			+ (curr.tv_usec - last.tv_usec);
		    printf(" - %g sec %d obj (%d contigs)\n", delta/1000000.0,
			   nobj - last_obj, ncontigs - last_contigs);
		    last = curr;
		    last_obj = nobj;
		    last_contigs = ncontigs;
		}
		fflush(stdout);
	    }
	}
#endif
    }
    
    if (pair && !a->fast_mode) {  
	finish_pairs(io, pair);
    }
    
    if (co)
	baf_block_destroy(co);

    cache_flush(io);
    zfclose(fp);

    printf("\nLoaded %12d contigs\n",     ncontigs);
    printf("       %12d sequences\n",   nseqs);
    printf("       %12d annotations\n", ntags);

    if (pair) delete_pair(pair);

    if (c)
	cache_decr(io, c);

    return 0;
}
Exemple #7
0
void qse_rbt_clear (rbt_t* rbt)
{
	/* TODO: improve this */
	while (!IS_NIL(rbt,rbt->root)) delete_pair (rbt, rbt->root);
}
static ci_status_e change_identity_basic(ucred_t const* uc, bool is_permanent) {
    // Sanity check for ids and sups
    if (!ids_are_sane(uc) ||
        !sups_are_sane(&uc->sups)) {
        return ci_invalid_values;
    }

    // Construct state pair: <current state, target state>
    pcred_pair_t p;
    ci_status_e status = fill_pair(uc, is_permanent, false, &p);

    // Back out immediately if transition is impossible
    if (status != ci_success) {
        delete_pair(&p);
        return status;
    }

    norm_pcred_pair_t const np = get_normalized_pcred_pair(&p);

    // Determine when to change groups: first, last, or elevate-before-change
    bool const must_change_sups = sups_change_needed(&np);
    bool const must_change_groups = groups_change_needed(&np);
    bool const current_priv = suid_privilege_is_effective(&p.prev.uids);
    bool const target_priv = suid_privilege_is_effective(&p.next.uids);
    bool const no_priv = !suid_privilege_is_attainable(
        np.prev.normalized.uids,
        np.next.normalized.uids);
    groups_timing_e const groups_timing =
        (no_priv || current_priv) ?
        groups_first :
        (target_priv ?
         groups_last :
         groups_elevate);

    switch (groups_timing) {
    default:
        assert(false);
        break;
    case groups_first:
        DPN(3, "Changing identity (basic): groups_first");
        break;
    case groups_last:
        DPN(3, "Changing identity (basic): groups_last");
        break;
    case groups_elevate:
        DPN(3, "Changing identity (basic): groups_elevate");
        break;
    }

    if (groups_timing == groups_elevate) {
        // The whole process is managed differently if we need to elevate
        // privileges to set sups before continuing to the final state
        change_identity_elevate_for_sups(&np);
    } else {

        if (groups_timing == groups_first) {
            // First change (triggered by no_priv or current_priv):

            if (must_change_groups) {
                // TODO: We do not currently have a graph of groups so there is
                // no guarantee that the group functions will work; however, by
                // doing them first when no_priv, we avoid the need for a
                // rollback if they fail
                if (set_gids_from_graph(&np) != 0) {
                    return ci_setgid_failed;
                }
            }

            if (must_change_sups) {
                assert(set_sups(&np.next.sups) == 0);
            }
        }

        assert(set_uids_from_graph(&np) == 0);

        if (groups_timing == groups_last) {
            // Last change (triggered by target_priv and not no_priv or
            // current_priv):
            if (must_change_sups) {
                assert(set_sups(&np.next.sups) == 0);
            }
            if (must_change_groups) {
                assert(set_gids_from_graph(&np) == 0);
            }
        }
    }

    delete_pair(&p);
    return ci_success;
}