Exemple #1
0
int chgrp_main(int argc, char **argv)
{
	long gid;
	int recursiveFlag;
	int retval = EXIT_SUCCESS;
	char *p;

	recursiveFlag = bb_getopt_ulflags(argc, argv, "R");

	if (argc - optind < 2) {
		bb_show_usage();
	}

	argv += optind;

	/* Find the selected group */
	gid = strtoul(*argv, &p, 10);	/* maybe it's already numeric */
	if (*p || (p == *argv)) {		/* trailing chars or nonnumeric */
		gid = my_getgrnam(*argv);
	}
	++argv;

	/* Ok, ready to do the deed now */
	do {
		if (! recursive_action (*argv, recursiveFlag, FALSE, FALSE, 
								fileAction, fileAction, &gid)) {
			retval = EXIT_FAILURE;
		}
	} while (*++argv);

	return retval;
}
extern int id_main(int argc, char **argv)
{
	char user[9], group[9];
	long pwnam, grnam;
	int uid, gid;
	int flags;
#ifdef CONFIG_SELINUX
	int is_flask_enabled_flag = is_flask_enabled();
#endif

	flags = bb_getopt_ulflags(argc, argv, "ugrn");

	if (((flags & (JUST_USER | JUST_GROUP)) == (JUST_USER | JUST_GROUP))
		|| (argc > optind + 1)
	) {
		bb_show_usage();
	}

	if (argv[optind] == NULL) {
		if (flags & PRINT_REAL) {
			uid = getuid();
			gid = getgid();
		} else {
			uid = geteuid();
			gid = getegid();
		}
		my_getpwuid(user, uid);
	} else {
		safe_strncpy(user, argv[optind], sizeof(user));
	    gid = my_getpwnamegid(user);
	}
	my_getgrgid(group, gid);

	pwnam=my_getpwnam(user);
	grnam=my_getgrnam(group);

	if (flags & (JUST_GROUP | JUST_USER)) {
		char *s = group;
		if (flags & JUST_USER) {
			s = user;
			grnam = pwnam;
		}
		if (flags & NAME_NOT_NUMBER) {
			puts(s);
		} else {
			printf("%ld\n", grnam);
		}
	} else {
#ifdef CONFIG_SELINUX
		printf("uid=%ld(%s) gid=%ld(%s)", pwnam, user, grnam, group);
		if(is_flask_enabled_flag)
		{
			security_id_t mysid = getsecsid();
			char context[80];
			int len = sizeof(context);
			context[0] = '\0';
			if(security_sid_to_context(mysid, context, &len))
				strcpy(context, "unknown");
			printf(" context=%s\n", context);
		}
		else
			printf("\n");
#else
		printf("uid=%ld(%s) gid=%ld(%s)\n", pwnam, user, grnam, group);
#endif

	}

	bb_fflush_stdout_and_exit(0);
}
Exemple #3
0
extern int id_main(int argc, char **argv)
{
	int no_user = 0, no_group = 0, print_real = 0;
	int name_not_number = 0;
	char user[9], group[9];
	long gid;
	long pwnam, grnam;
	int opt;
	
	gid = 0;

	while ((opt = getopt(argc, argv, "ugrn")) > 0) {
		switch (opt) {
			case 'u':
				no_group++;
				break;
			case 'g':
				no_user++;
				break;
			case 'r':
				print_real++;
				break;
			case 'n':
				name_not_number++;
				break;
			default:
				show_usage();
		}
	}

	if (no_user && no_group) show_usage();

	if (argv[optind] == NULL) {
		if (print_real) {
			my_getpwuid(user, getuid());
			my_getgrgid(group, getgid());
		} else {
			my_getpwuid(user, geteuid());
			my_getgrgid(group, getegid());
		}
	} else {
		strncpy(user, argv[optind], 8);
		user[8] = '\0';
	    gid = my_getpwnamegid(user);
		my_getgrgid(group, gid);
	}

	pwnam=my_getpwnam(user);
	grnam=my_getgrnam(group);

	if (no_group) {
		if(name_not_number && user)
			puts(user);
		else
			printf("%ld\n", pwnam);
	} else if (no_user) {
		if(name_not_number && group)
			puts(group);
		else
			printf("%ld\n", grnam);
	} else {
		printf("uid=%ld(%s) gid=%ld(%s)\n", pwnam, user, grnam, group);
	}
	return(0);
}