Make getcredhostname() take a buffer and the buffer's size

as arguments.  The correct hostname is copied into the buffer
while having the prison's lock acquired in a jailed process'
case.

Reviewed by:	jhb, rwatson
This commit is contained in:
Robert Drehmel 2002-02-27 16:43:20 +00:00
parent 2e30d3b13c
commit ad1ff0997e
2 changed files with 13 additions and 4 deletions

View File

@ -241,10 +241,19 @@ jailed(cred)
/*
* Return the correct hostname for the passed credential.
*/
const char *
getcredhostname(cred)
void
getcredhostname(cred, buf, size)
struct ucred *cred;
char *buf;
size_t size;
{
return (jailed(cred) ? cred->cr_prison->pr_host : hostname);
if (jailed(cred)) {
mtx_lock(&cred->cr_prison->pr_mtx);
strncpy(buf, cred->cr_prison->pr_host, size);
mtx_unlock(&cred->cr_prison->pr_mtx);
}
else
strncpy(buf, hostname, size);
buf[size - 1] = '\0';
}

View File

@ -68,7 +68,7 @@ extern int jail_sysvipc_allowed;
struct ucred;
struct sockaddr;
int jailed __P((struct ucred *cred));
const char *getcredhostname __P((struct ucred *cred));
void getcredhostname __P((struct ucred *cred, char *, size_t));
int prison_check __P((struct ucred *cred1, struct ucred *cred2));
void prison_free __P((struct prison *pr));
u_int32_t prison_getip __P((struct ucred *cred));