From owner-svn-src-all@FreeBSD.ORG Sat Jun 13 00:12:03 2009 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 8FE80106564A; Sat, 13 Jun 2009 00:12:03 +0000 (UTC) (envelope-from jamie@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 7D0608FC14; Sat, 13 Jun 2009 00:12:03 +0000 (UTC) (envelope-from jamie@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n5D0C3AD097257; Sat, 13 Jun 2009 00:12:03 GMT (envelope-from jamie@svn.freebsd.org) Received: (from jamie@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n5D0C31Y097253; Sat, 13 Jun 2009 00:12:03 GMT (envelope-from jamie@svn.freebsd.org) Message-Id: <200906130012.n5D0C31Y097253@svn.freebsd.org> From: Jamie Gritton Date: Sat, 13 Jun 2009 00:12:02 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r194090 - in head/sys: compat/linux compat/svr4 kern sys X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 13 Jun 2009 00:12:04 -0000 Author: jamie Date: Sat Jun 13 00:12:02 2009 New Revision: 194090 URL: http://svn.freebsd.org/changeset/base/194090 Log: Add counterparts to getcredhostname: getcreddomainname, getcredhostuuid, getcredhostid Suggested by: rmacklem Approved by: bz Modified: head/sys/compat/linux/linux_misc.c head/sys/compat/svr4/svr4_stat.c head/sys/kern/kern_jail.c head/sys/sys/jail.h Modified: head/sys/compat/linux/linux_misc.c ============================================================================== --- head/sys/compat/linux/linux_misc.c Sat Jun 13 00:06:52 2009 (r194089) +++ head/sys/compat/linux/linux_misc.c Sat Jun 13 00:12:02 2009 (r194090) @@ -716,7 +716,6 @@ linux_newuname(struct thread *td, struct struct l_new_utsname utsname; char osname[LINUX_MAX_UTSNAME]; char osrelease[LINUX_MAX_UTSNAME]; - struct prison *pr; char *p; #ifdef DEBUG @@ -730,6 +729,7 @@ linux_newuname(struct thread *td, struct bzero(&utsname, sizeof(utsname)); strlcpy(utsname.sysname, osname, LINUX_MAX_UTSNAME); getcredhostname(td->td_ucred, utsname.nodename, LINUX_MAX_UTSNAME); + getcreddomainname(td->td_ucred, utsname.domainname, LINUX_MAX_UTSNAME); strlcpy(utsname.release, osrelease, LINUX_MAX_UTSNAME); strlcpy(utsname.version, version, LINUX_MAX_UTSNAME); for (p = utsname.version; *p != '\0'; ++p) @@ -739,11 +739,6 @@ linux_newuname(struct thread *td, struct } strlcpy(utsname.machine, linux_platform, LINUX_MAX_UTSNAME); - pr = td->td_ucred->cr_prison; - mtx_lock(&pr->pr_mtx); - strlcpy(utsname.domainname, pr->pr_domain, LINUX_MAX_UTSNAME); - mtx_unlock(&pr->pr_mtx); - return (copyout(&utsname, args->buf, sizeof(utsname))); } Modified: head/sys/compat/svr4/svr4_stat.c ============================================================================== --- head/sys/compat/svr4/svr4_stat.c Sat Jun 13 00:06:52 2009 (r194089) +++ head/sys/compat/svr4/svr4_stat.c Sat Jun 13 00:12:02 2009 (r194090) @@ -411,10 +411,10 @@ svr4_sys_systeminfo(td, uap) struct thread *td; struct svr4_sys_systeminfo_args *uap; { - struct prison *pr; char *str = NULL; int error = 0; register_t *retval = td->td_retval; + u_long hostid; size_t len = 0; char buf[MAXHOSTNAMELEN]; u_int rlen = uap->len; @@ -458,10 +458,8 @@ svr4_sys_systeminfo(td, uap) break; case SVR4_SI_HW_SERIAL: - pr = td->td_ucred->cr_prison; - mtx_lock(&pr->pr_mtx); - snprintf(buf, sizeof(buf), "%lu", pr->pr_hostid); - mtx_unlock(&pr->pr_mtx); + getcredhostid(td->td_ucred, &hostid); + snprintf(buf, sizeof(buf), "%lu", hostid); str = buf; break; @@ -470,10 +468,7 @@ svr4_sys_systeminfo(td, uap) break; case SVR4_SI_SRPC_DOMAIN: - pr = td->td_ucred->cr_prison; - mtx_lock(&pr->pr_mtx); - strlcpy(buf, pr->pr_domain, sizeof(buf)); - mtx_unlock(&pr->pr_mtx); + getcreddomainname(td->td_ucred, buf, sizeof(buf)); str = buf; break; Modified: head/sys/kern/kern_jail.c ============================================================================== --- head/sys/kern/kern_jail.c Sat Jun 13 00:06:52 2009 (r194089) +++ head/sys/kern/kern_jail.c Sat Jun 13 00:12:02 2009 (r194090) @@ -3207,19 +3207,50 @@ jailed(struct ucred *cred) } /* - * Return the correct hostname for the passed credential. + * Return the correct hostname (domainname, et al) for the passed credential. */ void getcredhostname(struct ucred *cred, char *buf, size_t size) { struct prison *pr; + /* + * A NULL credential can be used to shortcut to the physical + * system's hostname. + */ pr = (cred != NULL) ? cred->cr_prison : &prison0; mtx_lock(&pr->pr_mtx); strlcpy(buf, pr->pr_host, size); mtx_unlock(&pr->pr_mtx); } +void +getcreddomainname(struct ucred *cred, char *buf, size_t size) +{ + + mtx_lock(&cred->cr_prison->pr_mtx); + strlcpy(buf, cred->cr_prison->pr_domain, size); + mtx_unlock(&cred->cr_prison->pr_mtx); +} + +void +getcredhostuuid(struct ucred *cred, char *buf, size_t size) +{ + + mtx_lock(&cred->cr_prison->pr_mtx); + strlcpy(buf, cred->cr_prison->pr_uuid, size); + mtx_unlock(&cred->cr_prison->pr_mtx); +} + +void +getcredhostid(struct ucred *cred, unsigned long *hostid) +{ + + mtx_lock(&cred->cr_prison->pr_mtx); + *hostid = cred->cr_prison->pr_hostid; + mtx_unlock(&cred->cr_prison->pr_mtx); +} + /* * Determine whether the subject represented by cred can "see" * status of a mount point. Modified: head/sys/sys/jail.h ============================================================================== --- head/sys/sys/jail.h Sat Jun 13 00:06:52 2009 (r194089) +++ head/sys/sys/jail.h Sat Jun 13 00:12:02 2009 (r194090) @@ -304,7 +304,10 @@ struct mount; struct sockaddr; struct statfs; int jailed(struct ucred *cred); -void getcredhostname(struct ucred *cred, char *, size_t); +void getcredhostname(struct ucred *, char *, size_t); +void getcreddomainname(struct ucred *, char *, size_t); +void getcredhostuuid(struct ucred *, char *, size_t); +void getcredhostid(struct ucred *, unsigned long *); int prison_allow(struct ucred *, unsigned); int prison_check(struct ucred *cred1, struct ucred *cred2); int prison_canseemount(struct ucred *cred, struct mount *mp);