-.\" $OpenBSD: chroot.8,v 1.14 2010/07/08 06:52:30 jmc Exp $
+.\" $OpenBSD: chroot.8,v 1.15 2015/05/19 16:05:12 millert Exp $
.\"
.\" Copyright (c) 1988, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
.\" from: @(#)chroot.8 8.1 (Berkeley) 6/9/93
.\"
-.Dd $Mdocdate: July 8 2010 $
+.Dd $Mdocdate: May 19 2015 $
.Dt CHROOT 8
.Os
.Sh NAME
databases unless overridden by the
.Fl g
option.
+Additional settings may be applied as specified in
+.Xr login.conf 5
+depending on
+.Ar user Ns 's
+login class.
.El
.Sh ENVIRONMENT
.Bl -tag -width SHELL
.Sh SEE ALSO
.Xr ldd 1 ,
.Xr group 5 ,
+.Xr login.conf 5 ,
.Xr passwd 5 ,
.Xr environ 7
.Sh HISTORY
-/* $OpenBSD: chroot.c,v 1.13 2009/10/27 23:59:51 deraadt Exp $ */
+/* $OpenBSD: chroot.c,v 1.14 2015/05/19 16:05:12 millert Exp $ */
/*
* Copyright (c) 1988, 1993
#include <errno.h>
#include <grp.h>
#include <limits.h>
+#include <login_cap.h>
#include <paths.h>
#include <pwd.h>
#include <stdio.h>
{
struct group *grp;
struct passwd *pwd;
+ login_cap_t *lc;
const char *shell;
char *user, *group, *grouplist;
gid_t gidlist[NGROUPS_MAX];
int ch, ngids;
+ int flags = LOGIN_SETALL & ~(LOGIN_SETLOGIN|LOGIN_SETUSER);
+ lc = NULL;
ngids = 0;
pwd = NULL;
user = grouplist = NULL;
if (argc < 1)
usage();
- if (user != NULL && (pwd = getpwnam(user)) == NULL)
- errx(1, "no such user `%s'", user);
+ if (user != NULL) {
+ if ((pwd = getpwnam(user)) == NULL)
+ errx(1, "no such user `%s'", user);
+ if ((lc = login_getclass(pwd->pw_class)) == NULL)
+ err(1, "unable to get login class for `%s'", user);
+ }
while ((group = strsep(&grouplist, ",")) != NULL) {
if (*group == '\0')
err(1, "setgid");
if (setgroups(ngids, gidlist) != 0)
err(1, "setgroups");
- } else if (pwd != NULL) {
- if (setgid(pwd->pw_gid) != 0)
- err(1, "setgid");
- if (initgroups(user, pwd->pw_gid) == -1)
- err(1, "initgroups");
+ flags &= ~LOGIN_SETGROUP;
+ }
+ if (lc != NULL) {
+ if (setusercontext(lc, pwd, pwd->pw_uid, flags) == -1)
+ err(1, "setusercontext");
}
if (chroot(argv[0]) != 0 || chdir("/") != 0)
setlogin(pwd->pw_name);
if (setuid(pwd->pw_uid) != 0)
err(1, "setuid");
- endgrent();
}
if (argv[1]) {