mirror of
https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git
synced 2024-11-15 06:42:51 +01:00
o Fix error messages formatting, style.
Prodded by: bde Reviewed by: bde
This commit is contained in:
parent
5053d272c2
commit
b026ec0eb8
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=112972
@ -34,7 +34,7 @@ main(int argc, char **argv)
|
|||||||
struct jail j;
|
struct jail j;
|
||||||
struct passwd *pwd;
|
struct passwd *pwd;
|
||||||
struct in_addr in;
|
struct in_addr in;
|
||||||
int ch, groups[NGROUPS], i, ngroups;
|
int ch, groups[NGROUPS], ngroups;
|
||||||
char *username;
|
char *username;
|
||||||
|
|
||||||
username = NULL;
|
username = NULL;
|
||||||
@ -56,44 +56,36 @@ main(int argc, char **argv)
|
|||||||
if (username != NULL) {
|
if (username != NULL) {
|
||||||
pwd = getpwnam(username);
|
pwd = getpwnam(username);
|
||||||
if (pwd == NULL)
|
if (pwd == NULL)
|
||||||
err(1, "getpwnam %s", username);
|
err(1, "getpwnam: %s", username);
|
||||||
lcap = login_getpwclass(pwd);
|
lcap = login_getpwclass(pwd);
|
||||||
if (lcap == NULL)
|
if (lcap == NULL)
|
||||||
err(1, "getpwclass failed", username);
|
err(1, "getpwclass: %s", username);
|
||||||
ngroups = NGROUPS;
|
ngroups = NGROUPS;
|
||||||
i = getgrouplist(username, pwd->pw_gid, groups, &ngroups);
|
if (getgrouplist(username, pwd->pw_gid, groups, &ngroups) != 0)
|
||||||
if (i)
|
err(1, "getgrouplist: %s", username);
|
||||||
err(1, "getgrouplist %s", username);
|
|
||||||
}
|
}
|
||||||
i = chdir(argv[0]);
|
if (chdir(argv[0]) != 0)
|
||||||
if (i)
|
err(1, "chdir: %s", argv[0]);
|
||||||
err(1, "chdir %s", argv[0]);
|
|
||||||
memset(&j, 0, sizeof(j));
|
memset(&j, 0, sizeof(j));
|
||||||
j.version = 0;
|
j.version = 0;
|
||||||
j.path = argv[0];
|
j.path = argv[0];
|
||||||
j.hostname = argv[1];
|
j.hostname = argv[1];
|
||||||
i = inet_aton(argv[2], &in);
|
if (inet_aton(argv[2], &in) == 0)
|
||||||
if (!i)
|
errx(1, "Could not make sense of ip-number: %s", argv[2]);
|
||||||
errx(1, "Couldn't make sense of ip-number\n");
|
|
||||||
j.ip_number = ntohl(in.s_addr);
|
j.ip_number = ntohl(in.s_addr);
|
||||||
i = jail(&j);
|
if (jail(&j) != 0)
|
||||||
if (i)
|
err(1, "jail");
|
||||||
err(1, "Imprisonment failed");
|
|
||||||
if (username != NULL) {
|
if (username != NULL) {
|
||||||
i = setgroups(ngroups, groups);
|
if (setgroups(ngroups, groups) != 0)
|
||||||
if (i)
|
err(1, "setgroups");
|
||||||
err(1, "setgroups failed");
|
if (setgid(pwd->pw_gid) != 0)
|
||||||
i = setgid(pwd->pw_gid);
|
err(1, "setgid");
|
||||||
if (i)
|
if (setusercontext(lcap, pwd, pwd->pw_uid,
|
||||||
err(1, "setgid failed");
|
LOGIN_SETALL & ~LOGIN_SETGROUP) != 0)
|
||||||
i = setusercontext(lcap, pwd, pwd->pw_uid,
|
err(1, "setusercontext");
|
||||||
LOGIN_SETALL & ~LOGIN_SETGROUP);
|
|
||||||
if (i)
|
|
||||||
err(1, "setusercontext failed");
|
|
||||||
}
|
}
|
||||||
i = execv(argv[3], argv + 3);
|
if (execv(argv[3], argv + 3) != 0)
|
||||||
if (i)
|
err(1, "execv: %s", argv[3]);
|
||||||
err(1, "execv(%s)", argv[3]);
|
|
||||||
exit (0);
|
exit (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,6 +93,7 @@ static void
|
|||||||
usage(void)
|
usage(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
errx(1,
|
(void)fprintf(stderr, "%s\n",
|
||||||
"Usage: jail [-u username] path hostname ip-number command ...");
|
"Usage: jail [-u username] path hostname ip-number command ...");
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user