Exemplo n.º 1
0
struct group *
getgrgid(gid_t gid)
{
	struct group *p_gr = (struct group*)_THREAD_PRIVATE(gr, _gr_group, NULL);
	struct group_storage *gs = (struct group_storage *)_THREAD_PRIVATE(gr_storage,
	    gr_storage, NULL);

	return getgrgid_gs(gid, p_gr, gs);
}
Exemplo n.º 2
0
struct group *
getgrnam(const char *name)
{
	struct group *p_gr = (struct group*)_THREAD_PRIVATE(gr,_gr_group,NULL);
	struct group_storage *gs = (struct group_storage *)_THREAD_PRIVATE(gr_storage,
	    gr_storage, NULL);

	return getgrnam_gs(name, p_gr, gs);
}
Exemplo n.º 3
0
struct group *
_getgrent_yp(int *foundyp)
{
	struct group *p_gr = (struct group*)_THREAD_PRIVATE(gr, _gr_group, NULL);
	struct group_storage *gs = (struct group_storage *)_THREAD_PRIVATE(gr_storage,
	    gr_storage, NULL);

	_THREAD_PRIVATE_MUTEX_LOCK(gr);
	if ((!_gr_fp && !start_gr()) || !grscan(0, 0, NULL, p_gr, gs, foundyp))
		p_gr = NULL;
	_THREAD_PRIVATE_MUTEX_UNLOCK(gr);
	return (p_gr);
}
Exemplo n.º 4
0
void
endhostent(void)
{
	struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res);

	_resp->options &= ~(RES_STAYOPEN | RES_USEVC);
	res_close();
}
Exemplo n.º 5
0
void
sethostent(int stayopen)
{
	struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res);

	if (_res_init(0) == -1)
		return;
	if (stayopen)
		_resp->options |= RES_STAYOPEN | RES_USEVC;
}
Exemplo n.º 6
0
    static void
    Perror(FILE *file, char *string, int error)
    {
	struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res);
	int save = errno;

	if (_resp->options & RES_DEBUG) {
		fprintf(file, "res_send: %s: %s\n",
			string, strerror(error));
	}
	errno = save;
    }
Exemplo n.º 7
0
char *
asctime(const struct tm *timeptr)
{
	static char result[MAX_ASCTIME_BUF_SIZE];
	_THREAD_PRIVATE_KEY(asctime);
	char *resultp = (char *)_THREAD_PRIVATE(asctime, result, NULL);

	if (resultp == NULL)
		return NULL;
	else
		return asctime3(timeptr, resultp, sizeof(result));
}
Exemplo n.º 8
0
/*
 * pick appropriate nsaddr_list for use.  see res_init() for initialization.
 */
static struct sockaddr *
get_nsaddr(size_t n)
{
	struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res);
	struct __res_state_ext *_res_extp = _THREAD_PRIVATE(_res_ext, _res_ext,
							    &_res_ext);

	if (!_resp->nsaddr_list[n].sin_family) {
		/*
		 * - _res_extp->nsaddr_list[n] holds an address that is larger
		 *   than struct sockaddr, and
		 * - user code did not update _resp->nsaddr_list[n].
		 */
		return (struct sockaddr *)&_res_extp->nsaddr_list[n];
	} else {
		/*
		 * - user code updated _res.nsaddr_list[n], or
		 * - _resp->nsaddr_list[n] has the same content as
		 *   _res_extp->nsaddr_list[n].
		 */
		return (struct sockaddr *)&_resp->nsaddr_list[n];
	}
}
Exemplo n.º 9
0
char *
getlogin(void)
{
	_THREAD_PRIVATE_KEY(getlogin);
	char * name = (char *)_THREAD_PRIVATE(getlogin, logname, NULL);

	if ((errno = getlogin_r(name, sizeof logname)) != 0)
		return NULL;
	if (*name == '\0') {
		errno = ENOENT;  /* well? */
		return NULL;
	}
	return name;
}
Exemplo n.º 10
0
    static void
    Aerror(FILE *file, char *string, int error, struct sockaddr *address)
    {
	struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res);
	int save = errno;

	if (_resp->options & RES_DEBUG) {
		if (getnameinfo(address, address->sa_len, abuf, sizeof(abuf),
		    pbuf, sizeof(pbuf), NI_NUMERICHOST | NI_NUMERICSERV) != 0) {
			strlcpy(abuf, "?", sizeof(abuf));
			strlcpy(pbuf, "?", sizeof(pbuf));
		}
		fprintf(file, "res_send: %s ([%s].%s): %s\n",
			string, abuf, pbuf, strerror(error));
	}
	errno = save;
    }
Exemplo n.º 11
0
char *
ttyname(int fd)
{
	_THREAD_PRIVATE_KEY(ttyname);
	char * bufp = (char*) _THREAD_PRIVATE(ttyname, buf, NULL);
	int err;

	if (bufp == NULL) 
		return NULL;
	err = ttyname_r(fd, bufp, sizeof buf);
	if (err) {
		errno = err;
		return NULL;
	}
	else
	return bufp;
}
Exemplo n.º 12
0
/*
 * Free the "asr" async resolver (or the thread-local resolver if NULL).
 * Drop the reference to the current context.
 */
void
_asr_resolver_done(void *arg)
{
	struct asr *asr = arg;
	struct asr **priv;

	if (asr == NULL) {
		priv = _THREAD_PRIVATE(_asr, _asr, &_asr);
		if (*priv == NULL)
			return;
		asr = *priv;
		*priv = NULL;
	}

	_asr_ctx_unref(asr->a_ctx);
	free(asr);
}
Exemplo n.º 13
0
/* int
 * res_isourserver(ina)
 *	looks up "ina" in _resp->ns_addr_list[]
 * returns:
 *	0  : not found
 *	>0 : found
 * author:
 *	paul vixie, 29may94
 */
int
res_isourserver(const struct sockaddr_in *inp)
{
	struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res);
#ifdef INET6
	const struct sockaddr_in6 *in6p = (const struct sockaddr_in6 *)inp;
	const struct sockaddr_in6 *srv6;
#endif
	const struct sockaddr_in *srv;
	int ns, ret;

	ret = 0;
	switch (inp->sin_family) {
#ifdef INET6
	case AF_INET6:
		for (ns = 0; ns < _resp->nscount; ns++) {
			srv6 = (struct sockaddr_in6 *)get_nsaddr(ns);
			if (srv6->sin6_family == in6p->sin6_family &&
			    srv6->sin6_port == in6p->sin6_port &&
			    srv6->sin6_scope_id == in6p->sin6_scope_id &&
			    (IN6_IS_ADDR_UNSPECIFIED(&srv6->sin6_addr) ||
			     IN6_ARE_ADDR_EQUAL(&srv6->sin6_addr,
			         &in6p->sin6_addr))) {
				ret++;
				break;
			}
		}
		break;
#endif
	case AF_INET:
		for (ns = 0; ns < _resp->nscount; ns++) {
			srv = (struct sockaddr_in *)get_nsaddr(ns);
			if (srv->sin_family == inp->sin_family &&
			    srv->sin_port == inp->sin_port &&
			    (srv->sin_addr.s_addr == INADDR_ANY ||
			     srv->sin_addr.s_addr == inp->sin_addr.s_addr)) {
				ret++;
				break;
			}
		}
		break;
	}
	return (ret);
}
Exemplo n.º 14
0
/*
 * Get a context from the given resolver. This takes a new reference to
 * the returned context, which *must* be explicitely dropped when done
 * using this context.
 */
struct asr_ctx *
_asr_use_resolver(void *arg)
{
	struct asr *asr = arg;
	struct asr **priv;

	if (asr == NULL) {
		DPRINT("using thread-local resolver\n");
		priv = _THREAD_PRIVATE(_asr, _asr, &_asr);
		if (*priv == NULL) {
			DPRINT("setting up thread-local resolver\n");
			*priv = _asr_resolver();
		}
		asr = *priv;
	}
	if (asr != NULL) {
		asr_check_reload(asr);
		asr_ctx_ref(asr->a_ctx);
		return (asr->a_ctx);
	}
	return (NULL);
}