Esempio n. 1
0
void fileaction_setowngrp(char *filename, int fileref)
{
    int uid, gid;
    uid = bb_xgetpwnam(rpm_getstring(RPMTAG_FILEUSERNAME, fileref));
    gid = bb_xgetgrnam(rpm_getstring(RPMTAG_FILEGROUPNAME, fileref));
    chown (filename, uid, gid);
}
Esempio n. 2
0
int id_main(int argc, char **argv)
{
	struct passwd *p;
	uid_t uid;
	gid_t gid;
	unsigned long flags;
	short status;

	/* Don't allow -n -r -nr -ug -rug -nug -rnug */
	/* Don't allow more than one username */
	bb_opt_complementally = "?1:?:u--g:g--u:r?ug:n?ug";
	flags = bb_getopt_ulflags(argc, argv, "rnug");

	/* This values could be overwritten later */
	uid = geteuid();
	gid = getegid();
	if (flags & PRINT_REAL) {
		uid = getuid();
		gid = getgid();
	}

	if(argv[optind]) {
		p=getpwnam(argv[optind]);
		/* bb_xgetpwnam is needed because it exits on failure */
		uid = bb_xgetpwnam(argv[optind]);
		gid = p->pw_gid;
		/* in this case PRINT_REAL is the same */
	}

	if(flags & (JUST_GROUP | JUST_USER)) {
		/* JUST_GROUP and JUST_USER are mutually exclusive */
		if(flags & NAME_NOT_NUMBER) {
			/* bb_getpwuid and bb_getgrgid exit on failure so puts cannot segfault */
			puts((flags & JUST_USER) ? bb_getpwuid(NULL, uid, -1 ) : bb_getgrgid(NULL, gid, -1 ));
		} else {
			bb_printf("%u\n",(flags & JUST_USER) ? uid : gid);
		}
		/* exit */
		bb_fflush_stdout_and_exit(EXIT_SUCCESS);
	}

	/* Print full info like GNU id */
	/* bb_getpwuid doesn't exit on failure here */
	status=printf_full(uid, bb_getpwuid(NULL, uid, 0), 'u');
	putchar(' ');
	/* bb_getgrgid doesn't exit on failure here */
	status|=printf_full(gid, bb_getgrgid(NULL, gid, 0), 'g');

	putchar('\n');
	bb_fflush_stdout_and_exit(status);
}
Esempio n. 3
0
int
start_stop_daemon_main(int argc, char **argv)
{
	unsigned long opt;
	char *signame = NULL;
	char *startas = NULL;

	bb_applet_long_options = ssd_long_options;

	/* Check required one context option was given */
	bb_opt_complementally = "K:S:?:K--S:S--K";
	opt = bb_getopt_ulflags(argc, argv, "KSbqma:n:s:u:x:p:",
		&startas, &cmdname, &signame, &userspec, &execname, &pidfile);

	
	quiet = opt & SSD_OPT_QUIET;

	if (signame) {
		signal_nr = bb_xgetlarg(signame, 10, 0, NSIG);
	}

	if (!execname && !pidfile && !userspec && !cmdname)
		bb_error_msg_and_die ("need at least one of -x, -p, -u, or -n");

	if (!startas)
		startas = execname;

	if ((opt & SSD_CTX_START) && !startas)
		bb_error_msg_and_die ("-S needs -x or -a");

	if ((opt & SSD_OPT_MAKEPID) && pidfile == NULL)
		bb_error_msg_and_die ("-m needs -p");

	argc -= optind;
	argv += optind;

	if (userspec && sscanf(userspec, "%d", &user_id) != 1)
		user_id = bb_xgetpwnam(userspec);

	if (opt & SSD_CTX_STOP) {
		do_stop();
		return EXIT_SUCCESS;
	}

	do_procinit();

	if (found) {
		if (!quiet)
			printf("%s already running.\n%d\n", execname ,found->pid);
		return EXIT_SUCCESS;
	}
	*--argv = startas;
	if (opt & SSD_OPT_BACKGROUND) {
		if (daemon(0, 0) == -1)
			bb_perror_msg_and_die ("unable to fork");
		setsid();
	}
	if (opt & SSD_OPT_MAKEPID) {
		/* user wants _us_ to make the pidfile */
		FILE *pidf = fopen(pidfile, "w");
		pid_t pidt = getpid();
		if (pidf == NULL)
			bb_perror_msg_and_die("Unable to write pidfile '%s'", pidfile);
		fprintf(pidf, "%d\n", pidt);
		fclose(pidf);
	}
	execv(startas, argv);
	bb_perror_msg_and_die ("unable to start %s", startas);
}
Esempio n. 4
0
int id_main(int argc, char **argv)
{
	struct passwd *p;
	uid_t uid;
	gid_t gid;
	unsigned long flags;
	short status;
#ifdef CONFIG_SELINUX
	security_context_t scontext;
#endif

	/* Don't allow -n -r -nr -ug -rug -nug -rnug */
	/* Don't allow more than one username */
	bb_opt_complementally = "?1:?:u--g:g--u:r?ug:n?ug";
	flags = bb_getopt_ulflags(argc, argv, "rnugZ");

	/* This values could be overwritten later */
	uid = geteuid();
	gid = getegid();
	if (flags & PRINT_REAL) {
		uid = getuid();
		gid = getgid();
	}

	if(argv[optind]) {
		p=getpwnam(argv[optind]);
		/* bb_xgetpwnam is needed because it exits on failure */
		uid = bb_xgetpwnam(argv[optind]);
		gid = p->pw_gid;
		/* in this case PRINT_REAL is the same */
	}

#ifdef CONFIG_SELINUX
	if(flags & (JUST_GROUP | JUST_USER | JUST_CONTEXT )) {
#else
	if(flags & (JUST_GROUP | JUST_USER )) {
#endif
		/* JUST_GROUP and JUST_USER are mutually exclusive */
		if(flags & NAME_NOT_NUMBER) {
			/* bb_getpwuid and bb_getgrgid exit on failure so puts cannot segfault */
			puts((flags & JUST_USER) ? bb_getpwuid(NULL, uid, -1 ) : bb_getgrgid(NULL, gid, -1 ));
		} else {
			if (flags & JUST_USER){
				bb_printf("%u\n",uid);
			}
			if (flags & JUST_GROUP){
				bb_printf("%u\n",gid);
			}
		}

#ifdef CONFIG_SELINUX
		if(flags & JUST_CONTEXT){
			if( !is_selinux_enabled() ) {
				bb_error_msg_and_die("Sorry, --context (-Z) can be used only on "
									 "a selinux-enabled kernel.\n" );			
			}
			if (argc - optind == 1){
				bb_error_msg("cannot print security context when user specified");					
				bb_fflush_stdout_and_exit(EXIT_FAILURE);
			}

			if (getcon(&scontext)){
				bb_error_msg("can't get process context");		
				bb_fflush_stdout_and_exit(EXIT_FAILURE);
			}
			bb_printf("%s\n", scontext);
		}
#endif
		/* exit */
		bb_fflush_stdout_and_exit(EXIT_SUCCESS);
	}

	/* Print full info like GNU id */
	/* bb_getpwuid doesn't exit on failure here */
	status=printf_full(uid, bb_getpwuid(NULL, uid, 0), 'u');
	putchar(' ');
	/* bb_getgrgid doesn't exit on failure here */
	status|=printf_full(gid, bb_getgrgid(NULL, gid, 0), 'g');
	

#ifdef CONFIG_SELINUX
	if ( is_selinux_enabled() ) {
			security_context_t mysid;
			char context[80];
			int len = sizeof(context);

			getcon(&mysid);
			context[0] = '\0';
			if (mysid) {
					len = strlen(mysid)+1;
					safe_strncpy(context, mysid, len);
					freecon(mysid);
			}else{
					safe_strncpy(context, "unknown",8);
			}
		bb_printf(" context=%s", context);
	}
#endif

	putchar('\n');
	bb_fflush_stdout_and_exit(status);
}