- while (argc > 0) {
- cp = *argv;
- if (*cp == '-') {
- switch (*++cp) {
- case 'u': no_group = 1; break;
- case 'g': no_user = 1; break;
- case 'r': print_real = 1; break;
- default: usage(id_usage);
- }
- } else {
- user = cp;
- }
- argc--; argv++;
+ 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 */