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

Chroot for ossec-logtest #864

Merged
merged 1 commit into from
Jun 21, 2016
Merged
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
26 changes: 24 additions & 2 deletions src/analysisd/testrule.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ int main(int argc, char **argv)
char *ut_str = NULL;
const char *dir = DEFAULTDIR;
const char *cfg = DEFAULTCPATH;
const char *user = USER;
const char *group = GROUPGLOBAL;
uid_t uid;
gid_t gid;

/* Set the name */
OS_SetName(ARGV0);
Expand Down Expand Up @@ -142,9 +146,23 @@ int main(int argc, char **argv)
}
}

if (chdir(dir) != 0) {
/* Check if the user/group given are valid */
uid = Privsep_GetUser(user);
gid = Privsep_GetGroup(group);
if (uid == (uid_t) - 1 || gid == (gid_t) - 1) {
ErrorExit(USER_ERROR, ARGV0, user, group);
}

/* Set the group */
if (Privsep_SetGroup(gid) < 0) {
ErrorExit(SETGID_ERROR, ARGV0, group, errno, strerror(errno));
}

/* Chroot */
if (Privsep_Chroot(dir) < 0) {
ErrorExit(CHROOT_ERROR, ARGV0, dir, errno, strerror(errno));
}
nowChroot();

/*
* Anonymous Section: Load rules, decoders, and lists
Expand Down Expand Up @@ -269,6 +287,11 @@ int main(int argc, char **argv)
exit(0);
}

/* Set the user */
if (Privsep_SetUser(uid) < 0) {
ErrorExit(SETUID_ERROR, ARGV0, user, errno, strerror(errno));
}

/* Start up message */
verbose(STARTUP_MSG, ARGV0, getpid());

Expand Down Expand Up @@ -571,4 +594,3 @@ void OS_ReadMSG(char *ut_str)
}
exit(exit_code);
}