jexec.c (194709) | jexec.c (194869) |
---|---|
1/*- 2 * Copyright (c) 2003 Mike Barcroft <mike@FreeBSD.org> 3 * Copyright (c) 2008 Bjoern A. Zeeb <bz@FreeBSD.org> 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 10 unchanged lines hidden (view full) --- 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * | 1/*- 2 * Copyright (c) 2003 Mike Barcroft <mike@FreeBSD.org> 3 * Copyright (c) 2008 Bjoern A. Zeeb <bz@FreeBSD.org> 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 10 unchanged lines hidden (view full) --- 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * |
27 * $FreeBSD: head/usr.sbin/jexec/jexec.c 194709 2009-06-23 14:40:08Z jamie $ | 27 * $FreeBSD: head/usr.sbin/jexec/jexec.c 194869 2009-06-24 18:18:35Z jamie $ |
28 */ 29 30#include <sys/param.h> 31#include <sys/jail.h> 32#include <sys/socket.h> 33#include <sys/sysctl.h> | 28 */ 29 30#include <sys/param.h> 31#include <sys/jail.h> 32#include <sys/socket.h> 33#include <sys/sysctl.h> |
34#include <sys/uio.h> | |
35 36#include <arpa/inet.h> 37#include <netinet/in.h> 38 39#include <err.h> 40#include <errno.h> | 34 35#include <arpa/inet.h> 36#include <netinet/in.h> 37 38#include <err.h> 39#include <errno.h> |
40#include <jail.h> |
|
41#include <limits.h> 42#include <login_cap.h> 43#include <stdio.h> 44#include <stdlib.h> 45#include <string.h> 46#include <pwd.h> 47#include <unistd.h> 48 --- 13 unchanged lines hidden (view full) --- 62 ngroups = ngroups_max; \ 63 if (getgrouplist(username, pwd->pw_gid, groups, &ngroups) != 0) \ 64 err(1, "getgrouplist: %s", username); \ 65} while (0) 66 67int 68main(int argc, char *argv[]) 69{ | 41#include <limits.h> 42#include <login_cap.h> 43#include <stdio.h> 44#include <stdlib.h> 45#include <string.h> 46#include <pwd.h> 47#include <unistd.h> 48 --- 13 unchanged lines hidden (view full) --- 62 ngroups = ngroups_max; \ 63 if (getgrouplist(username, pwd->pw_gid, groups, &ngroups) != 0) \ 64 err(1, "getgrouplist: %s", username); \ 65} while (0) 66 67int 68main(int argc, char *argv[]) 69{ |
70 struct iovec params[2]; | |
71 int jid; 72 login_cap_t *lcap = NULL; 73 struct passwd *pwd = NULL; 74 gid_t *groups = NULL; 75 int ch, ngroups, uflag, Uflag; 76 long ngroups_max; | 70 int jid; 71 login_cap_t *lcap = NULL; 72 struct passwd *pwd = NULL; 73 gid_t *groups = NULL; 74 int ch, ngroups, uflag, Uflag; 75 long ngroups_max; |
77 char *ep, *username; | 76 char *username; |
78 79 ch = uflag = Uflag = 0; 80 username = NULL; 81 ngroups_max = sysconf(_SC_NGROUPS_MAX) + 1; 82 if ((groups = malloc(sizeof(gid_t) * ngroups_max)) == NULL) 83 err(1, "malloc"); 84 85 while ((ch = getopt(argc, argv, "nu:U:")) != -1) { --- 16 unchanged lines hidden (view full) --- 102 argc -= optind; 103 argv += optind; 104 if (argc < 2) 105 usage(); 106 if (uflag && Uflag) 107 usage(); 108 if (uflag) 109 GET_USER_INFO; | 77 78 ch = uflag = Uflag = 0; 79 username = NULL; 80 ngroups_max = sysconf(_SC_NGROUPS_MAX) + 1; 81 if ((groups = malloc(sizeof(gid_t) * ngroups_max)) == NULL) 82 err(1, "malloc"); 83 84 while ((ch = getopt(argc, argv, "nu:U:")) != -1) { --- 16 unchanged lines hidden (view full) --- 101 argc -= optind; 102 argv += optind; 103 if (argc < 2) 104 usage(); 105 if (uflag && Uflag) 106 usage(); 107 if (uflag) 108 GET_USER_INFO; |
110 jid = strtoul(argv[0], &ep, 10); 111 if (!*argv[0] || *ep) { 112 *(const void **)¶ms[0].iov_base = "name"; 113 params[0].iov_len = sizeof("name"); 114 params[1].iov_base = argv[0]; 115 params[1].iov_len = strlen(argv[0]) + 1; 116 jid = jail_get(params, 2, 0); 117 if (jid < 0) 118 errx(1, "Unknown jail: %s", argv[0]); 119 } | 109 jid = jail_getid(argv[0]); 110 if (jid < 0) 111 errx(1, "%s", jail_errmsg); |
120 if (jail_attach(jid) == -1) | 112 if (jail_attach(jid) == -1) |
121 err(1, "jail_attach(): %d", jid); | 113 err(1, "jail_attach(%d)", jid); |
122 if (chdir("/") == -1) 123 err(1, "chdir(): /"); 124 if (username != NULL) { 125 if (Uflag) 126 GET_USER_INFO; 127 if (setgroups(ngroups, groups) != 0) 128 err(1, "setgroups"); 129 if (setgid(pwd->pw_gid) != 0) --- 19 unchanged lines hidden --- | 114 if (chdir("/") == -1) 115 err(1, "chdir(): /"); 116 if (username != NULL) { 117 if (Uflag) 118 GET_USER_INFO; 119 if (setgroups(ngroups, groups) != 0) 120 err(1, "setgroups"); 121 if (setgid(pwd->pw_gid) != 0) --- 19 unchanged lines hidden --- |