<commit_before>#include <errno.h>
#include <pwd.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>

const char *user;
struct passwd *pw;
int errsv;

int main (int argc, char *const *argv, char *const *envp) {
	if (argc < 3) {
		printf ("Usage:\n  %s <USER> <COMMAND> [ARGS]\n", argv [0]);
		return (1);
	}
	
	user = *++argv;
	argv++;
	pw = getpwnam (user);
	if (! pw) {
		printf ("Error: Unknown account: %s\n", user);
		return (1);
	}

	if (setgid (pw->pw_gid) == -1) {
		errsv = errno;
		printf ("Error: Failed to set GID to %i: %s\n", (int) pw->pw_gid, strerror (errsv));
		return (1);
	}
	if (setuid (pw->pw_uid) == -1) {
		errsv = errno;
		printf ("Error: Failed to set UID to %i: %s\n", (int) pw->pw_uid, strerror (errsv));
		return (1);
	}

	execve (*argv, argv, envp);
	errsv = errno;
	printf ("Error: Failed to run %s: %s\n", *argv, strerror (errsv));
	return (1);
}
<commit_msg>Checks for root or target user<commit_after>#include <errno.h>
#include <pwd.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>

const char *user;
struct passwd *pw;
int errsv;

int main (int argc, char *const *argv, char *const *envp) {
	if (argc < 3) {
		printf ("Usage:\n  %s <USER> <COMMAND> [ARGS]\n", argv [0]);
		return (1);
	}
	
	user = *++argv;
	argv++;
	pw = getpwnam (user);
	if (! pw) {
		printf ("Error: Unknown account: %s\n", user);
		return (1);
	}

	if ((geteuid () != 0) && (geteuid () != pw->pw_uid)) {
		printf ("Error: Not running as root or the target user\n");
		return (1);
	}

	if ((geteuid () == 0) {
		if (setgid (pw->pw_gid) == -1) {
			errsv = errno;
			printf ("Error: Failed to set GID to %i: %s\n", (int) pw->pw_gid, strerror (errsv));
			return (1);
		}
		if (setuid (pw->pw_uid) == -1) {
			errsv = errno;
			printf ("Error: Failed to set UID to %i: %s\n", (int) pw->pw_uid, strerror (errsv));
			return (1);
		}
	}

	execve (*argv, argv, envp);
	errsv = errno;
	printf ("Error: Failed to run %s: %s\n", *argv, strerror (errsv));
	return (1);
}

{'fraction_non_alphanumeric': 0.20884520884520885, 'fraction_numerical': 0.010319410319410319, 'mean_word_length': 3.4649122807017543, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '840647', 'n_tokens_mistral': 929, 'n_tokens_neox': 865, 'n_words': 263}