예제 #1
0
ktap_eventdef_info *ktapc_parse_events(const char *eventdef)
{
	char *str = strdup(eventdef);
	char *sys, *event, *filter, *next;
	ktap_eventdef_info *evdef_info;
	int ret;

	idmap_init();

 parse_next_eventdef:
	next = get_next_eventdef(str);

	if (get_sys_event_filter_str(str, &sys, &event, &filter))
		goto error;

	verbose_printf("parse_eventdef: sys[%s], event[%s], filter[%s]\n",
		       sys, event, filter);

	if (!strcmp(sys, "probe"))
		ret = parse_events_add_probe(event);
	else if (!strcmp(sys, "sdt"))
		ret = parse_events_add_sdt(event);
	else
		ret = parse_events_add_tracepoint(sys, event);

	if (ret)
		goto error;

	/* don't trace ftrace:function when all tracepoints enabled */
	if (!strcmp(sys, "*"))
		idmap_clear(1);


	if (filter && *next != '\0') {
		fprintf(stderr, "Error: eventdef only can append one filter\n");
		goto error;
	}

	str = next;
	if (*next != '\0')
		goto parse_next_eventdef;

	evdef_info = malloc(sizeof(*evdef_info));
	if (!evdef_info)
		goto error;

	evdef_info->nr = id_nr;
	evdef_info->id_arr = get_id_array();
	evdef_info->filter = filter;

	idmap_free();
	return evdef_info;
 error:
	idmap_free();
	cleanup_event_resources();
	return NULL;
}
예제 #2
0
static void
_freemember(struct member* m) {
    if (m->delaymap) {
        idmap_free(m->delaymap, _freecb);
        m->delaymap = NULL;
    }
    if (m->buffmap) {
        idmap_free(m->buffmap, _freecb);
        m->buffmap = NULL;
    }
}
예제 #3
0
파일: author_lda.c 프로젝트: nionjo/dm
int init_author_lda(AuthorLda * alda){

    IdMap * uidmap = idmap_create();
    IdMap * vidmap = idmap_create();
    IdMap * aidmap = idmap_create();

    if (0 != load_author(alda, uidmap, aidmap)){
        goto free_maps;
    }
    fprintf(stderr, "author load done, doc : %d, author : %d\n", alda->D, alda->A);

    if (0 != load_tokens(alda, uidmap, vidmap, aidmap)){
        goto free_author;
    }
    fprintf(stderr, "tokens laod done, tokens : %d, words : %d\n", alda->T, alda->V);

    alda->nkw = (int*)malloc(sizeof(int) * alda->p.k);
    memset(alda->nkw, 0, sizeof(int) * alda->p.k);

#ifdef PHI
    if (0 != load_phi(alda, vidmap)){
        goto free_author;
    }
    fprintf(stderr, "phi load done\n");
#endif

    return 0;

free_author:
    free_author_lda(alda);

free_maps:
    idmap_free(uidmap);   uidmap = NULL;
    idmap_free(vidmap);   vidmap = NULL;
    idmap_free(aidmap);   aidmap = NULL;

    return -1;
}
예제 #4
0
static nss_status_t
getbyuid(ad_backend_ptr be, void *a)
{
	nss_XbyY_args_t		*argp = (nss_XbyY_args_t *)a;
	char			searchfilter[ADUTILS_MAXHEXBINSID + 14];
	char			*sidprefix = NULL;
	idmap_rid_t		rid;
	char			cbinsid[ADUTILS_MAXHEXBINSID + 1];
	char			*winname = NULL, *windomain = NULL;
	int			is_user, is_wuser;
	gid_t			gid;
	idmap_stat		idmaprc;
	int			ret, try_idmap;
	nss_status_t		stat;

	be->db_type = NSS_AD_DB_PASSWD_BYUID;

	stat = (nss_status_t)NSS_NOTFOUND;

	/* nss_ad does not support non ephemeral uids */
	if (argp->key.uid <= MAXUID)
		goto out;

	/* Map the given UID to a SID using the idmap service */
	if (idmap_get_u2w_mapping(&argp->key.uid, NULL, 0,
	    1, NULL, &sidprefix, &rid, &winname, &windomain,
	    NULL, NULL) != 0) {
		RESET_ERRNO();
		goto out;
	}

	/*
	 * NULL winname implies a local SID or unresolvable SID both of
	 * which cannot be used to generated passwd(4) entry
	 */
	if (winname == NULL)
		goto out;

	/* If this is not a Well-Known SID try AD lookup */
	if (windomain != NULL && strcasecmp(windomain, WK_DOMAIN) != 0) {
		if (adutils_txtsid2hexbinsid(sidprefix, &rid,
		    &cbinsid[0], sizeof (cbinsid)) != 0)
			goto out;

		ret = snprintf(searchfilter, sizeof (searchfilter),
		    _F_GETPWUID, cbinsid);
		if (ret >= sizeof (searchfilter) || ret < 0)
			goto out;

		stat = _nss_ad_lookup(be, argp, _PASSWD, searchfilter,
		    windomain, &try_idmap);

		if (!try_idmap)
			goto out;
	}

	/* Map winname to primary gid using idmap service */
	is_user = 0;
	is_wuser = -1;
	idmaprc = idmap_get_w2u_mapping(NULL, NULL,
	    winname, windomain, 0, &is_user, &is_wuser, &gid,
	    NULL, NULL, NULL);

	if (idmaprc != IDMAP_SUCCESS) {
		RESET_ERRNO();
		goto out;
	}

	/* Create passwd(4) style string */
	if (update_buffer(be, argp, winname, windomain,
	    argp->key.uid, gid, "", "", "") < 0)
		goto out;

	/* Marshall the data, sanitize the return status and return */
	stat = _nss_ad_marshall_data(be, argp);
	stat = _nss_ad_sanitize_status(be, argp, stat);

out:
	idmap_free(sidprefix);
	idmap_free(winname);
	idmap_free(windomain);
	return (stat);
}
예제 #5
0
파일: lda.c 프로젝트: nionjo/dm
int init_lda(Lda *lda) {
    FILE *fp = NULL;
    if (NULL == (fp = fopen(lda->p.in_file, "r"))) {
        fprintf(stderr, "can not open file \"%s\"\n", lda->p.in_file);
        return -1;
    }
    char buffer[LDA_LINE_LEN];
    char **str_array = NULL;
    int count = 0, token_size = 0;

    IdMap *uidmap = idmap_create();
    IdMap *vidmap = idmap_create();

    while (NULL != fgets(buffer, LDA_LINE_LEN, fp)) {
        str_array = split(trim(buffer, 3), '\t', &count);
        if (count < 2) {
            goto free_str;
        }

        if (-1 == idmap_get_value(uidmap, str_array[0])) {
            idmap_add(uidmap, dupstr(str_array[0]), idmap_size(uidmap));
        }

        if (-1 == idmap_get_value(vidmap, str_array[1])) {
            idmap_add(vidmap, dupstr(str_array[1]), idmap_size(vidmap));
        }
        token_size += 1;

free_str:
        free(str_array[0]);
        free(str_array);
    }

    lda->d = idmap_size(uidmap);
    lda->t = token_size;
    lda->v = idmap_size(vidmap);

    malloc_space(lda);

    rewind(fp);
    int uid = -1, vid = -1, tid = -1;
    int token_index = 0;

    while (NULL != fgets(buffer, LDA_LINE_LEN, fp)) {
        str_array = split(trim(buffer, 3), '\t', &count);
        if (count < 2) {
            goto str_free;
        }

        uid = idmap_get_value(uidmap, str_array[0]);
        strncpy(lda->id_doc_map[uid], str_array[0], KEY_SIZE - 1);
        lda->tokens[token_index][0] = uid;

        vid = idmap_get_value(vidmap, str_array[1]);
        strncpy(lda->id_v_map[vid], str_array[1], KEY_SIZE - 1);
        lda->tokens[token_index][1] = vid;

        tid = (int) ((1.0 + rand()) / (1.0 + RAND_MAX) * (lda->p.k));
        if (count == 3){
            tid = atoi(str_array[2]);
        }

        lda->tokens[token_index][2] = tid;
        token_index += 1;

str_free:
        free(str_array[0]);
        free(str_array);
    }
    fclose(fp);

    idmap_free(uidmap);   uidmap = NULL;
    idmap_free(vidmap);   vidmap = NULL;

    return 0;
}
예제 #6
0
/* ARGSUSED1 */
void
nfsmapid_gid_str(struct mapid_arg *argp, size_t arg_size)
{
	struct mapid_res	 result;
	struct mapid_res	*resp;
	struct group		 grp;
	struct group		*grp_ptr;
	char			*grp_buf = NULL;
	char			*idmap_buf = NULL;
	idmap_stat		 rc;
	gid_t			 gid = argp->u_arg.gid;
	size_t			 gid_str_len;
	char			*gr_str;
	size_t			 gr_str_len;
	char			*at_str;
	size_t			 at_str_len;
	char			 dom_str[DNAMEMAX];
	size_t			 dom_str_len;

	if (gid == (gid_t)-1) {
		/*
		 * Sentinel gid is not a valid id
		 */
		resp = &result;
		resp->status = NFSMAPID_BADID;
		resp->u_res.len = 0;
		goto done;
	}

	/*
	 * Make local copy of domain for further manipuation
	 * NOTE: mapid_get_domain() returns a ptr to TSD.
	 */
	if (cur_domain_null()) {
		dom_str_len = 0;
		dom_str[0] = '\0';
	} else {
		dom_str_len = strlen(mapid_get_domain());
		bcopy(mapid_get_domain(), dom_str, dom_str_len);
		dom_str[dom_str_len] = '\0';
	}

	/*
	 * If gid is ephemeral then resolve it using idmap service
	 */
	if (gid > UID_MAX) {
		rc = idmap_getwinnamebygid(gid, &idmap_buf, NULL);
		if (rc != IDMAP_SUCCESS) {
			/*
			 * We don't put stringified ephemeral gids on
			 * the wire.
			 */
			resp = &result;
			resp->status = NFSMAPID_UNMAPPABLE;
			resp->u_res.len = 0;
			goto done;
		}

		/*
		 * idmap_buf is already in the desired form i.e. name@domain
		 */
		gr_str = idmap_buf;
		gr_str_len = strlen(gr_str);
		at_str_len = dom_str_len = 0;
		at_str = "";
		dom_str[0] = '\0';
		goto gen_result;
	}

	/*
	 * Handling non-ephemeral gids
	 *
	 * We want to encode the gid into a literal string... :
	 *
	 *	- upon failure to allocate space from the heap
	 *	- if there is no current domain configured
	 *	- if there is no such gid in the group DB's
	 */
	if ((grp_buf = malloc(grp_buflen)) == NULL || dom_str_len == 0 ||
	    getgrgid_r(gid, &grp, grp_buf, grp_buflen, &grp_ptr) != 0 ||
	    grp_ptr == NULL) {

		/*
		 * If we could not allocate from the heap, try
		 * allocating from the stack as a last resort.
		 */
		if (grp_buf == NULL && (grp_buf =
		    alloca(MAPID_RES_LEN(UID_MAX_STR_LEN))) == NULL) {
			resp = &result;
			resp->status = NFSMAPID_INTERNAL;
			resp->u_res.len = 0;
			goto done;
		}

		/*
		 * Constructing literal string without '@' so that
		 * we'll know that it's not a group, but rather a
		 * gid encoded string.
		 */
		gr_str = grp_buf;
		(void) sprintf(gr_str, "%u", gid);
		gr_str_len = strlen(gr_str);
		at_str_len = dom_str_len = 0;
		at_str = "";
		dom_str[0] = '\0';
	} else {
		/*
		 * Otherwise, we construct the "group@domain" string if
		 * it's not already in that form.
		 */
		gr_str = grp.gr_name;
		gr_str_len = strlen(gr_str);
		if (strchr(gr_str, '@') == NULL) {
			at_str = "@";
			at_str_len = 1;
		} else {
			at_str_len = dom_str_len = 0;
			at_str = "";
			dom_str[0] = '\0';
		}
	}

gen_result:
	gid_str_len = gr_str_len + at_str_len + dom_str_len;
	if ((resp = alloca(MAPID_RES_LEN(gid_str_len))) == NULL) {
		resp = &result;
		resp->status = NFSMAPID_INTERNAL;
		resp->u_res.len = 0;
		goto done;
	}
	/* LINTED format argument to sprintf */
	(void) sprintf(resp->str, "%s%s%s", gr_str, at_str, dom_str);
	resp->u_res.len = gid_str_len;
	if (grp_buf)
		free(grp_buf);
	if (idmap_buf)
		idmap_free(idmap_buf);
	resp->status = NFSMAPID_OK;

done:
	/*
	 * There is a chance that the door_return will fail because the
	 * resulting string is too large, try to indicate that if possible
	 */
	if (door_return((char *)resp,
	    MAPID_RES_LEN(resp->u_res.len), NULL, 0) == -1) {
		resp->status = NFSMAPID_INTERNAL;
		resp->u_res.len = 0;
		(void) door_return((char *)&result, sizeof (struct mapid_res),
		    NULL, 0);
	}
}