Exemplo n.º 1
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);
}
Exemplo n.º 2
0
//=====================================================
int trans()//转置
{


		int i,j,s,t;


		int d[4][4]={0};
	//	if(c[][]==1&&c[][]==1&&c[][]==1&&c[][]==1)
			if(line_mark==1)
			{
				screen_a[m][n-2]=screen_a[m][n-1]=screen_a[m][n+1]=1;
				screen_a[m-2][n]=screen_a[m-1][n]=screen_a[m+1][n]=0;
				line_mark=0;
				find_mark();
				printf_full();
				return 1;
			}

			if(line_mark==2)
			{
				screen_a[m-2][n]=screen_a[m-1][n]=screen_a[m+1][n]=1;
				screen_a[m][n-2]=screen_a[m][n-1]=screen_a[m][n+1]=0;
				line_mark=0;
				find_mark();
				printf_full();
				return 1;
			}



			for(i=m,s=2;i<m+3;s--,i++)
			for(j=n-1,t=0;j<n+2;t++,j++)
                if(screen_a[i][j]<2)
				d[t][s]=screen_a[i][j];
	//	for(i=m-1,s=3;i<4;i++,s--)
	//		for(j=1,t=1;j<4;j++,t++)
	//			b[t][s]=c[i][j];


			if(d[0][2]==1&&d[1][1]==1&&d[1][2]==1&&d[2][1]==1)
			{
				d[1][0]=d[2][0]=d[0][1]=1;
			    d[2][1]=d[0][2]=d[1][2]=0;

			}
			if(d[0][1]==1&&d[1][1]==1&&d[1][2]==1&&d[2][2]==1)
			{
				d[0][0]=d[1][0]=d[2][1]=1;
                d[1][2]=d[2][2]=d[0][1]=0;

			}

			if(d[0][2]==1&&d[1][2]==1&&d[2][2]==1&&d[1][1]==1)
            {
                d[0][1]=d[1][1]=d[2][1]=d[1][0]=1;
                d[0][2]=d[1][2]=d[2][2]=0;

            }

            if(d[0][2]==1&&d[1][2]==1&&d[2][2]==1&&d[2][1]==1)
            {
                d[0][1]=d[1][1]=d[2][1]=d[2][0]=1;
                d[0][2]=d[1][2]=d[2][2]=0;

            }

            if(d[0][2]==1&&d[1][2]==1&&d[2][2]==1&&d[0][1]==1)

            {
                d[0][1]=d[1][1]=d[2][1]=d[0][0]=1;
                d[0][2]=d[1][2]=d[2][2]=0;
            }


			for(i=0,s=m;i<3;s++,i++)
				for(j=0,t=n-1;j<3;t++,j++)
                {
                if(d[i][j]==0)
                  if(screen_a[s][t]>=2)
                       continue;
                screen_a[s][t]=d[i][j];
                }
		//system("cls");
		find_mark();
		printf_full();
		return 1;



}
Exemplo n.º 3
0
extern int id_main(int argc, char **argv)
{
	struct passwd *p;
	uid_t uid;
	gid_t gid;
	unsigned long flags;
	short status;
#ifdef CONFIG_SELINUX
	int is_flask_enabled_flag = is_flask_enabled();
#endif

	bb_opt_complementaly = "u~g:g~u";
	flags = bb_getopt_ulflags(argc, argv, "rnug");

	if ((flags & BB_GETOPT_ERROR)
	/* Don't allow -n -r -nr */
	|| (flags <= 3 && flags > 0) 
	/* Don't allow more than one username */
	|| (argc > optind + 1))
		bb_show_usage();
	
	/* 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]);
		/* my_getpwnam is needed because it exits on failure */
		uid = my_getpwnam(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) {
			/* my_getpwuid and my_getgrgid exit on failure so puts cannot segfault */
			puts((flags & JUST_USER) ? my_getpwuid(NULL, uid, -1 ) : my_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 */
	/* my_getpwuid doesn't exit on failure here */
	status=printf_full(uid, my_getpwuid(NULL, uid, 0), 'u');
	putchar(' ');
	/* my_getgrgid doesn't exit on failure here */
	status|=printf_full(gid, my_getgrgid(NULL, gid, 0), 'g');
#ifdef CONFIG_SELINUX
	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");
		bb_printf(" context=%s", context);
	}
#endif
	putchar('\n');
	bb_fflush_stdout_and_exit(status);
}
Exemplo 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);
}