Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

draft: jail_unix: Simplify sub-argument matching #4202

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions bin/varnishd/mgt/mgt_jail_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,16 @@ vju_getccgid(const char *arg)
/**********************************************************************
*/

#define _MATCH_ARG(arg, name) \
(strncmp((arg), name "=", sizeof name) ? NULL : (arg) + sizeof name)

#define MATCH_ARG(var, arg, name) if (((var) = _MATCH_ARG(arg, #name)) != NULL)

static int v_matchproto_(jail_init_f)
vju_init(char **args)
{
const char *val;

if (args == NULL) {
/* Autoconfig */
if (geteuid() != 0)
Expand All @@ -132,31 +139,25 @@ vju_init(char **args)
ARGV_ERR("Unix Jail: Must be root.\n");

for (;*args != NULL; args++) {
const char * const a_user = "user=";
const size_t l_user = strlen(a_user);
if (!strncmp(*args, a_user, l_user)) {
if (vju_getuid((*args) + l_user))
MATCH_ARG(val, *args, user) {
if (vju_getuid(val))
ARGV_ERR(
"Unix jail: %s user not found.\n",
(*args) + 5);
val);
continue;
}
const char * const a_workuser = "workuser=";
const size_t l_workuser = strlen(a_workuser);
if (!strncmp(*args, a_workuser, l_workuser)) {
if (vju_getwrkuid((*args) + l_workuser))
MATCH_ARG(val, *args, workuser) {
if (vju_getwrkuid(val))
ARGV_ERR(
"Unix jail: %s user not found.\n",
(*args) + 9);
val);
continue;
}
const char * const a_ccgroup = "ccgroup=";
const size_t l_ccgroup = strlen(a_ccgroup);
if (!strncmp(*args, "ccgroup=", l_ccgroup)) {
if (vju_getccgid((*args) + l_ccgroup))
MATCH_ARG(val, *args, ccgroup) {
if (vju_getccgid(val))
ARGV_ERR(
"Unix jail: %s group not found.\n",
(*args) + 8);
val);
continue;
}
ARGV_ERR("Unix jail: unknown sub-argument '%s'\n",
Expand Down