summaryrefslogtreecommitdiffstats
path: root/sys/i386
diff options
context:
space:
mode:
authornate <nate@FreeBSD.org>1996-06-12 01:10:26 +0000
committernate <nate@FreeBSD.org>1996-06-12 01:10:26 +0000
commit120a4c2a81f784c25bd672b47e2ccde78dbcb5ca (patch)
tree04c78a99e4054bb9bfc2b63354dae5d68b55ac2a /sys/i386
parent94ca54ddd28985e6cbd836d5352b0cd5dfdeb4ff (diff)
downloadFreeBSD-src-120a4c2a81f784c25bd672b47e2ccde78dbcb5ca.zip
FreeBSD-src-120a4c2a81f784c25bd672b47e2ccde78dbcb5ca.tar.gz
Fixed GET/SETIPDOMAIN ioctl on /dev/socksys, which is used by various
other socket functions (gethostname() for one). Reviewed by: sef
Diffstat (limited to 'sys/i386')
-rw-r--r--sys/i386/ibcs2/ibcs2_socksys.c92
1 files changed, 90 insertions, 2 deletions
diff --git a/sys/i386/ibcs2/ibcs2_socksys.c b/sys/i386/ibcs2/ibcs2_socksys.c
index c95526d..a5527c4 100644
--- a/sys/i386/ibcs2/ibcs2_socksys.c
+++ b/sys/i386/ibcs2/ibcs2_socksys.c
@@ -35,10 +35,29 @@
#include <sys/ioctl.h>
#include <sys/sysproto.h>
#include <net/if.h>
+#include <sys/kernel.h>
+#include <sys/sysctl.h>
#include <i386/ibcs2/ibcs2_socksys.h>
#include <i386/ibcs2/ibcs2_util.h>
+/* Local structures */
+struct getipdomainname_args {
+ char *ipdomainname;
+ int len;
+};
+
+struct setipdomainname_args {
+ char *ipdomainname;
+ int len;
+};
+
+/* Local prototypes */
+static int ibcs2_getipdomainname __P((struct proc *,
+ struct getipdomainname_args *, int *));
+static int ibcs2_setipdomainname __P((struct proc *,
+ struct setipdomainname_args *, int *));
+
/*
* iBCS2 socksys calls.
*/
@@ -102,9 +121,9 @@ ibcs2_socksys(p, uap, retval)
case SOCKSYS_SELECT:
return select(p, passargs, retval);
case SOCKSYS_GETIPDOMAIN:
- return getdomainname(p, passargs, retval);
+ return ibcs2_getipdomainname(p, passargs, retval);
case SOCKSYS_SETIPDOMAIN:
- return setdomainname(p, passargs, retval);
+ return ibcs2_setipdomainname(p, passargs, retval);
case SOCKSYS_ADJTIME:
return adjtime(p, passargs, retval);
case SOCKSYS_SETREUID:
@@ -128,3 +147,72 @@ ibcs2_socksys(p, uap, retval)
}
/* NOTREACHED */
}
+
+/* ARGSUSED */
+static int
+ibcs2_getipdomainname(p, uap, retval)
+ struct proc *p;
+ struct getipdomainname_args *uap;
+ int *retval;
+{
+ char hname[MAXHOSTNAMELEN], *dptr;
+ int len;
+
+ /* Get the domain name */
+ strcpy(hname, hostname);
+ dptr = index(hname, '.');
+ if ( dptr )
+ dptr++;
+ else
+ /* Make it effectively an empty string */
+ dptr = hname + strlen(hname);
+
+ len = strlen(dptr) + 1;
+ if ((u_int)uap->len > len + 1)
+ uap->len = len + 1;
+ return (copyout((caddr_t)dptr, (caddr_t)uap->ipdomainname, uap->len));
+}
+
+/* ARGSUSED */
+static int
+ibcs2_setipdomainname(p, uap, retval)
+ struct proc *p;
+ struct setipdomainname_args *uap;
+ int *retval;
+{
+ char hname[MAXHOSTNAMELEN], *ptr;
+ int error, sctl[2], hlen;
+
+ if ((error = suser(p->p_ucred, &p->p_acflag)))
+ return (error);
+
+ /* W/out a hostname a domain-name is nonsense */
+ if ( strlen(hostname) == 0 )
+ return EINVAL;
+
+ /* Get the host's unqualified name (strip off the domain) */
+ strcpy(hname, hostname);
+ ptr = index(hname, '.');
+ if ( ptr != NULL ) {
+ ptr++;
+ *ptr = '\0';
+ } else
+ strcat(hname, ".");
+
+ /* Set ptr to the end of the string so we can append to it */
+ hlen = strlen(hname);
+ ptr = hname + hlen;
+ if ((u_int)uap->len > (sizeof (hname) - hlen - 1))
+ return EINVAL;
+
+ /* Append the ipdomain to the end */
+ error = copyin((caddr_t)uap->ipdomainname, ptr, uap->len);
+ if (error)
+ return (error);
+
+ /* 'sethostname' with the new information */
+ sctl[0] = CTL_KERN;
+ sctl[1] = KERN_HOSTNAME;
+ hlen = strlen(hname) + 1;
+ return (kernel_sysctl(p, sctl, 2, 0, 0, hname, hlen, 0));
+}
OpenPOWER on IntegriCloud