Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 13 Jun 2009 00:12:02 +0000 (UTC)
From:      Jamie Gritton <jamie@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r194090 - in head/sys: compat/linux compat/svr4 kern sys
Message-ID:  <200906130012.n5D0C31Y097253@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200906130012.n5D0C31Y097253>